Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nesting an ExpressionEngine Channel Entry Tag Pair within another Channel Entry Tag Pair?

I did some searching around but I can't seem to find any information on embedding a channel entry tag pair within another.

When I try the following code in a template, it breaks the page and I see the opening {reverse_related_entries sort="desc"} displayed as plain text:

{exp:channel:entries channel="pages"}
    {reverse_related_entries sort="desc"}
        {if show_testimonial}
            {exp:channel:entries channel="testimonials" orderby="random" limit="1"}
                <blockquote>
                    {testimony}
                    <cite>
                        <span class="cite_name">{cite_name}</span><br />
                        <span class="cite_org">{cite_org}</span><br />
                        <span class="cite_title">{cite_title}</span>
                    </cite>
                </blockquote>
            {/exp:channel:entries}
        {/if}
    {/reverse_related_entries}
{/exp:channel:entries}

Is there a way in ExpressionEngine to nest a channel entry tag pair inside itself?

like image 821
jchamb Avatar asked Dec 07 '11 00:12

jchamb


1 Answers

In order to nest a {exp:channel:entries} tag pair inside of itself, you'll need to embed the template within another template using an {embed} variable.

To do so, just modify your main channel entries tag to look like the following:

{exp:channel:entries channel="pages"}
    {reverse_related_entries sort="desc"}
        {if show_testimonial}
            {embed="template_group/template"}
        {/if}
    {/reverse_related_entries}
{/exp:channel:entries}

Then, create a new template with the contents of your nested channel entries tag pair:

{exp:channel:entries channel="testimonials" orderby="random" limit="1"}
    <blockquote>
        {testimony}
        <cite>
            <span class="cite_name">{cite_name}</span><br />
            <span class="cite_org">{cite_org}</span><br />
            <span class="cite_title">{cite_title}</span>
        </cite>
    </blockquote>
{/exp:channel:entries}

Which you can include in any ExpressionEngine template using the following syntax, as shown earlier:

{embed="template_group/template"}

Using embed templates are a standard way around some of ExpressionEngine's quirks and Parse Order (PDF, 32 KB), but they do carry a performance penalty with them so be mindful in deciding between using an {embed} and a {snippet}.

like image 98
rjb Avatar answered Sep 16 '22 16:09

rjb