croxton / Stash

Stash allows you to stash text and snippets of code for reuse throughout your templates.
GNU General Public License v3.0
197 stars 20 forks source link

Error when paring environment variable inside embed tag #170

Closed roberthallatt closed 2 years ago

roberthallatt commented 3 years ago

After upgrading to the latest version of Stash, if I include {user_language} as part of the value, it won't parse correctly.

{exp:stash:set_value name="top-menu-{user_language}" value="{stash:embed:partials:main-menu-{user_language}}"}

If I hardcode the language replcing {user_language} with en or fr, it works correctly. Not sure if this is an EE or Stash thing. Any ideas on how I might be able to get this working again?

croxton commented 3 years ago

That means the {user_language} variable hasn't been replaced with its value at the point the {exp:stash:set...} tag runs. You can use parse="inward" to tell a {exp:...} tag to parse variables passed in parameters.

{exp:stash:set_value name="top-menu-{user_language}" value="{stash:embed:partials:main-menu-{user_language}}" parse="inward"}

If I remember correctly (it's been a while!), you could also do without the set_variable and use an explicit name and filename to load your embed file into a variable:

{exp:stash:embed name="top-menu-{user_language}" file_name="partials:main-menu-{user_language}}" parse="inward" output="no" process="inline"}