ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Is it possible to use a conditional channel entry pair inside another channel entry pair (i.e. nested)?

January 15, 2011 8:18am

Subscribe [6]
  • #1 / Jan 15, 2011 8:18am

    bgarrant

    356 posts

    I opened a thread in Code Share Corner as well, but I have not been able to get an answer to the core question so I am coming to tech support.  Is it possible to use Nested Channel Pairs?  I cannot seem to make it work with version 2.1.3 and wanted to make sure it is even possible?  Basically I have a template for “subpages” and on one of the pages (entry_id=“1”) I need to display a small “gallery” matrix field. Here is code example which also has a Matrix filed in the call. I keep getting error when I save in CP that says…

    {exp:channel …

    No closing tag found. Note: some tags do not require closing.
    Please consult the module’s documentation if you experience problems.

    Please feel free to merge this forum thread with http://ellislab.com/forums/viewthread/178172/

    {exp:channel:entries channel="subpage" disable="categories|member_data|pagination"}
    <h2>{title}</h2>
    <p>{page_body}</p>
    
    <p>{if entry_id="1"}<br />
        {exp:channel:entries channel="galleries" entry_id="29"}<br />
            </p><h3>{title}</h3>
    <p>        {page_body}<br />
            <ul><br />
            {gallery}<br />
            <li class="gallery"><a href="http://{image_file}" rel="shadowbox" title="{image_title}">_        {exp:imgsizer:size src="{image_file}" width="100" height="100"}_        {sized}_        {/exp:imgsizer:size}__        {image_title}__</a></li><br />
            {/gallery}<br />
            </ul><br />
        {/exp:channel:entries}<br />
    {/if}</p>
    
    <p>{/exp:channel:entries}

    This other example without a Matix field also gives the same error about no closing tag…

    {exp:channel:entries channel="home" disable="categories|member_data|pagination" entry_id="2"}
    {embed="embeds/html_header_home" my_page_title="{title}" meta_description="{meta_description}" meta_keywords="{meta_keywords}" }
    
        <div id="hd">
             <div class="hd-429">
                <div class='slideshow'>
                {exp:channel:entries channel="slideshow" disable="categories|member_data|pagination"}
                {exp:imgsizer:size src="{slideshow}" width="373" height="280" alt="First Presbyterian Church"}
                {sized}
                {/exp:imgsizer:size}
                {/exp:channel:entries}
                </div>
            </div>
                <div class="hd-595">
                    {page_header}
            </div>
    {/exp:channel:entries}
          </div>
  • #2 / Jan 15, 2011 2:42pm

    JasonLeeLab

    53 posts

    You can accomplish this with an embed like so:

    {exp:channel:entries channel="subpage" disable="categories|member_data|pagination"}
    <h2>{title}</h2>
    <p>{page_body}</p>
    
    <p>{if entry_id="1"}<br />
       {embed="includes/show-gallery"}<br />
    {/if}</p>
    
    <p>{/exp:channel:entries}

    And the contents of your ‘includes/show-gallery’:

    {exp:channel:entries channel="galleries" entry_id="29" dynamic="no"}
            <h3>{title}</h3>
    <p>        {page_body}<br />
            <ul><br />
            {gallery}<br />
            <li class="gallery"><a href="http://{image_file}" rel="shadowbox" title="{image_title}">_        {exp:imgsizer:size src="{image_file}" width="100" height="100"}_        {sized}_        {/exp:imgsizer:size}__        {image_title}__</a></li><br />
            {/gallery}<br />
            </ul><br />
     {/exp:channel:entries}

    Note: Use caution when nesting because it will slow down your page load speed.

  • #3 / Jan 15, 2011 7:36pm

    bgarrant

    356 posts

    I will try that Jason.  Thank you.

  • #4 / Jan 16, 2011 4:58pm

    Greg Salt

    3988 posts

    Hi bgarrant,

    Excellent. Jason’s advice here is spot on. In general, you should not nest tags. Please let us know how you get on.

    @Jason, thanks very much for the help.

    Cheers

    Greg

  • #5 / Jan 25, 2011 1:12pm

    Lisa Wess

    20502 posts

    just to build on what Greg said - for the code you have with that embed:

    {exp:channel:entries channel="subpage" disable="categories|member_data|pagination"}
    <h2>{title}</h2>
    <p>{page_body}</p>
    
    <p>{if entry_id="1"}<br />
       {embed="includes/show-gallery"}<br />
    {/if}</p>
    
    <p>{/exp:channel:entries}

    That is going to default to a limit=“100” - so all of your entries, or the first 100 entries, whichever comes first.

    That means your embed, which includes this:

    {exp:channel:entries channel="galleries" entry_id="29" dynamic="no"}
            <h3>{title}</h3>
    <p>        {page_body}<br />
            <ul><br />
            {gallery}<br />
            <li class="gallery"><a href="http://{image_file}" rel="shadowbox" title="{image_title}">_        {exp:imgsizer:size src="{image_file}" width="100" height="100"}_        {sized}_        {/exp:imgsizer:size}__        {image_title}__</a></li><br />
            {/gallery}<br />
            </ul><br />
     {/exp:channel:entries}

    Is going to run up to 100 times.

    ie: your channel entries tag is going to have to be looped through 100 times. 

    What I mean is this:

    For the first entry in your outer tag pair, the inner channel entries tag will loop one hundred times

    Then for the second entry in your outer tag pair, the inner channel entries tag will loop one hundred times.

    Rinse and repeat 98 more times.

    The entry ID is a natural limiter to 1 - but this should give you an idea of what you’re asking EE to do.

    This is strongly discouraged. It will eat a lot of memory and processor.  I would recommend finding another route.

  • #6 / Jan 25, 2011 3:43pm

    narration

    773 posts

    Lisa, I may well be missing something, but somehow this doesn’t sound quite right.

    - for the outer loop, you are not going to loop through 100 available entries unless you forgot to use paging, etc.. In that case you would have trouble even without an embed, so this won’t normally happen. The loop might go 5 times, typically, and on each of those 5 it’s doing something useful not given in the cut-down example code: it’s displaying the entry, normally.

    - because of the condition on only showing the gallery on one of the entries, you are not going to run the embed code more than once, no matter how many overall entries you have.

    - I couldn’t quite get the rest, where it seems you think the embed would loop 100 times for every one of the (not really) 100 outer loops. The embed is similarly going to run as many times as you allow images on a page - again 5-20 would be a reasonable range, and it is not going to repeat that. In other words it’s a normal gallery.

    I appreciate I think what you are worried about, and the answers for cases where there truly might be a lot of data to search would be to use query tags and/or the effect of a database-limited SQL query by conditioning entry_id, yes?

    That way databases and their indexes do the work, rather than a looping construct of any kind, and take advantage of all the constraints you responsibly must put on what data you really want to view.

    I think the embed scenario is a good way to use EE tags when you need an inner entries listing—and in fact it must be done that way if you want to take advantage of EE’s tags rather than writing PHP or SQL in larger scale.

    Am I wrong about this, or…? I also would feel that if there really were a good reason not to do a thing, more needs to be said about how to accomplish it than that you must find another way. 

    Somehow I do think you’d agree about that, and maybe that points to some of the positive tasks which can build that enterprise scenario, one step at a time.

    Again, I am sure you’ll let me know if I’ve missed a point here.

    Regards,
    Clive

  • #7 / Jan 25, 2011 3:48pm

    bgarrant

    356 posts

    After doing some testing I also believe you have to embed the nested entry call.  It seems to show errors when I do not embed the code.  Seesm like it should be valid either way though as code is essentially the same on final rendered page.

  • #8 / Jan 25, 2011 3:52pm

    Lisa Wess

    20502 posts

    Clive, without any limit=, the entries tag will pull 100 entries before paginating.  I can only speak to the code as presented.

    We get complaints here, a fair bit, about EE’s speed and resource usage, where investigation brings us to the template coding.  Nesting entries tags can be extremely heavy, and that is why my warning is here - explaining how it works.

    Bryan - you can’t nest them without embedding, EE will confuse the opening and closing tags.

    Relationships can be a great way to connect two entries without the nesting of channel entries tags, and there may be other routes for connecting data that would be less intensive.  My goal here is simply to educate on how EE works and to help avoid problems on your sites down the line.

  • #9 / Jan 25, 2011 4:30pm

    narration

    773 posts

    Lisa, I do fully appreciate which end of things you are engaged in, and would like to close this way.

    - ExpressionEngine has proved itself a good and useful idea - a set of tags which can vastly simplify the usual sorts of web page construction; and most importantly, let designer/marketer people get rapid results.

    - EE is in fact embedded in a much more general framework which has been worked out over decades for solving business needs through software. That’s the framework you tap when you use query tags, or SQL and/or PHP in general, which EE allows.

    - Because it is not a programming language, and because of its simplifications to likely expected abilities such as logic and looping, EE can become rapidly frustrating beyond the direct cases it handles easily. That and, as you mention, unseen performance consequences of pushing some of its limitations certainly do surface with persons who innocently or not want to do more.

    - The use of patterns such as embeds to allow tag nesting actually helps a lot, because it avoids programming unless the case really needs it. It’s only necessary to be able to use good judgement, and that’s what I recommend Support help people to do - both encourage, and help the judgement be good. It’s a much more positive approach than ‘avoid because it might in edge cases be troublesome’.  Live in the environment, and help identify and smooth where edges can be - that’s comfortable.

    - Even more comfortable can be to build a visible and confident continuum out past the edges. All the tools are there, as your technical people know. I’m thinking the most attractive course is a nurturing of custom-built add-on approaches, which can solve problems that general case app-store add-ons and EE can’t, by themselves.

    - There are a lot of advantages to isolating special needs in their own mechanisms, and then making the mechanism simply available as another tag to use in the simple kind of EE template-building. And there are some very evident paths where Ellis can directly and indirectly continue and add value to their framework, by informing and encouraging the ways this can happen.

    Pass where you think it will do the most good, please. For today, I just wanted to say that sensibly handled, embed-nesting methods are surely something that has value for a number of people - several of them here today.

    Regards, Lisa,
    Clive

    hoping to have controlled the keyboard on lap so I don’t have to go back and edit this time 😉  Comfortable chairs will do that to you…

  • #10 / Jan 26, 2011 8:27am

    Sue Crocker

    26054 posts

    Hi, bgarrant.

    Has the question been answered OK?

    Thanks for the discussion, Clive. You may want to put this information in the form of a Feature Request.

  • #11 / Jan 26, 2011 8:44am

    bgarrant

    356 posts

    My original question has been answered Sue.  Thanks.

  • #12 / Jan 26, 2011 3:14pm

    Ingmar

    29245 posts

    Very glad to hear it. Please post again as needed.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases