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.

What better for performance: conditional around channel loop or channel loop around conditional.

September 05, 2012 5:57pm

Subscribe [1]
  • #1 / Sep 05, 2012 5:57pm

    danielcgold

    9 posts

    I’m testing out different options for dynamically displaying the single channel entry dynamically or all of the channel entries. What is better in terms of performance? Is there a better way to do this?

    {if segment_2 == ""}
     {exp:channel:entries channel="example_page" limit="1"}
      {title}
      {description}
     {/exp:channel:entries}
     
    {if:else}
     {exp:channel:entries channel="example_page"}
      {title}
     {/exp:channel:entries}
     
    {/if}

    or

    {exp:channel:entries channel="example_page"}
     {if segment_2 == ""}
      {title}
      {description}
      
     {if:else}
      {title}
     {/if}
    {/exp:channel:entries}
  • #2 / Sep 07, 2012 1:17pm

    Dan Decker

    7338 posts

    Hi Daniel,

    Thanks for your question!

    You should use 2 simple conditionals inside the channel entries pair:

    {exp:channel:entries channel="example_page"}
     {if segment_2 == ""}
      {title}
      {description}
     {/if} 
     {if segment_2 != ""}
      {title}
     {/if}
    {/exp:channel:entries}

    Wrapping the conditional around the channel entries pair could cause the tag to be parsed even if the condition isn’t met. That makes extra queries, processing time etc.

    Let me know if you have any questions!

    Cheers,

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

ExpressionEngine News!

#eecms, #events, #releases