jorblume
jorblume

Reputation: 607

ExpressionEngine: Conditional template embed

I'm having a bit of an issue with Expression Engine parse order and conditional logic.

I want to embed a template based on a conditional statement within a channel.

Something like this:

             {exp:channel:entries channel="project" limit="3"}
                      {if count >2}
                          <h1>title{/h1}
                       {if:else}
                        {embed="test/.test.html}
                       {/if}

             {/exp:channel:entries}

The problem is that the embed gets called multiple time from the loop. I tried using Stash to set a variable (then call the embed if the variable was set), but it's too late or too early in the parse order.

Does anyone know of a way to conditionally embed based on channel values?

Upvotes: 1

Views: 580

Answers (1)

AllInOne
AllInOne

Reputation: 1450

What version of EE are you using? EE 2.9 brings substantial changes (improvements!) to how conditionals are handled. I'm not on EE 2.9 yet but by my reading of the 'Rendering Stages' documentation what you are trying should work as written in 2.9.

Note that conditionals are evaluated in step 19 and embeds in step 21.

In earlier versions of EE embeds were processed before "complex conditionals". See the 2.9 announcement and changelog for details.

Upvotes: 1

Related Questions