Stash icon indicating copy to clipboard operation
Stash copied to clipboard

Error when paring environment variable inside embed tag

Open roberthallatt opened this issue 3 years ago • 1 comments

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?

roberthallatt avatar May 19 '21 16:05 roberthallatt

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"}

croxton avatar May 19 '21 17:05 croxton