1

In an upstream template, I do this code :

{embed="templatecategory/template" varA="{var1}" varB="{var2}"}

These variables are populated by a custom addon.

And in the next template:

{embed:varA}<br>
{if varA == 3}
    its 3!
{if:else}
    its not 3!
{/if}

The output is:

3

its not 3!

so the embedded variable works! its there!

I'm assuming that the conditional is being run before the variable resolves(parsing order issue). So, I've tried to use stash in the upstream template to no avail.

{exp:stash:set}
    {stash:StashVar}{var1}{/stash:StashVar} 
{/exp:stash:set}

And the downstream template is

<script> console.log("StashVar = {StashVar}")</script>
{stash:embed:StashVar}
<br>
{if StashVar == 3}
    its 3!
{if:else}
    its not 3!
{/if}

and again the output is

3
its not 3!

Note the console log I put in to see what is happening. If I run that command in the upstream template it correctly outputs

StashVar = 3

but downstream is

StashVar = {StashVar}

What's the easiest way to get those variables to the downstream template for use in conditionals?

3 Answers 3

2

I think your problem is that you're not using the correct variable name in the conditional. When you send a variable in an embed, the variable on the other end is {embed:variable_name}, not {variable_name}.

With that in mind, try the following...

{embed:varA}<br>
{if embed:varA == 3}
    its 3!
{if:else}
    its not 3!
{/if}

If that doesn't work, try

{embed:varA}<br>
{if "{embed:varA}" == "3"}
    its 3!
{if:else}
    its not 3!
{/if}
1
  • AAAAHHH such a simple solution that I spent sooo long on.
    – Eastmarch
    Commented Feb 16 at 22:03
-1

Why don't you just test the embed variable?

{!-- PAGE TEMPLATE --}
{exp:stash:set name="stashVar"}{var1}{/exp:stash:set}
{embed="group/template" stashVar="{exp:stash:get name='stashVar'}"}

Then...

{!-- EMBED TEMPLATE --}
{if embed:StashVar == 3}
    its 3!
{if:else}
    its not 3!
{/if}

I think it's slightly unclear what you are trying to accomplish because you changed variable names multiple times.

-1

If you are chaining templates (that's what it sounds like at least) these days you can usually avoid the need to use {embed} constructs much of the time through the use of Layout Variables.

Based on what it looks like you are trying to do, the advantage of Layout Variables for this use case comes as a side-effect of how Layout Templates are evaluated by EE - basically each template in a template layout stack is evaluated before processing moves on to the next one in the stack - so any layout variables you define on one layout template are evaluated before they are saved / made available in the next (and all subsequent) templates in the layout stack.

Because layout templates are evaluated in sequence, and thanks to how EE writes out template debug information, you also get a side-benefit in that you can inspect the values of all layout variables directly from the template debug report (as you can for the values assigned to embed variables actually).

HTH

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.