Use an additional variable in a block theme

Viewed 44

I managed to put a button in my theme following these instructions: https://doc.oroinc.com/frontend/storefront/templates/ but I wonder how to actually show a costum variables contents.

I defined "userName" via "vars" in mything.yml for mything.twig.html as shown in https://doc.oroinc.com/frontend/storefront/templates/#custom-variables , but

{{ text|trans({'%userName%': userName})}} 

shows the same text as before, I tried

{{ dump(_context) }} 

and the vars don't even turn up in the dumped variables.

1 Answers

Make sure the translation message is not an issue. You can do it within the UI: https://doc.oroinc.com/user/back-office/system/localization/translations/#localization-translations

Then, if you are working in a prod environment, make sure you cleared the cache after changes. In dev env, the cache is disabled for layouts.

If the above advices don't help, make sure you are setting the variable for the same block as the template where the variable is used, as the variables are scoped by block and not visible outside.

Also, you can use the Symfony dev toolbar to see the result blocks tree with all the set variables: https://doc.oroinc.com/frontend/storefront/debugging/#layout-tree

Related