0

In former days {assign_variable: my_var="foo"} was a very handy tool. I haven't used it for some time and discovered that it was deprecated in EE 4.x but was not able to determine what if anything it has been replaced with. Is there a "modern" equivalent? If so, would you mind sharing?

Thanks.

  • Do you mean assigning variables to an embed template? – Bluedreamer Jul 15 at 19:00
  • Yes. You create the variable at the top of the template and then you can use the variable values in the template. – forrest Jul 15 at 19:04
1

The best way of creating transient values within a template is through EE's built in layout variable system.

Layout variables can be defined as single values or as part of an addressable array, and can contain anything you can generate as tag output within a template.

The only wrinkle is that the variables only get instantiated when EE template processing transfers to a subsequent template (using EE's Template Layout system). So the most minimal way of defining and then using a variable would be something like this:

First Template in chain

{layout='template_2'}
{layout:set name="my_var" value="foo"}
{layout:set name="my_var_another_option"}foo{/layout:set}

Second Template in chain ('template_2')

<h1>Here is the content of my_var {layout:my_var}</h1>
<p>And here is the content of my_var_another_option {layout:my_var_another_option}.</p>

I'll leave you to read about the layout variable array option in the docs... :)

HTH

| improve this answer | |
  • Obviously not as simple as in times past. Thank you for your feedback. – forrest Jul 16 at 14:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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