Search code examples
shopware

Shopware 5 accessing controller variables (Template Variables) on frontend


The technical term given in many articles for this is Template Variables. I am trying to understand how we can find the variable name given in the controller for a specific field of Shopware 5 front end (ex. Product Name)

For example, I can see the template variable for article name has been given as $sArticle.articleName. I found this when I checked the source code manually.

Let’s say I want to find the discount value given for particular product, How can I print this on my theme? What variable I should use and what is the easy way to find it.

I can assign values from back end for all the variables but my question is how I can access them on my theme file when I update my theme when it comes to technical development side.

Please Note: I am trying to understand the shopware5 technical side.


Solution

  • If you want to use your variables inside the template you have to write a plugin and assign your controller-variables to the view.

    Check out Globale Variablen im Template verwenden in the shopware documentation.

    If you want to use see which variables are allready assigned, you can use {debug} in the template. Also {$sArticle|var_dump} is really helpful, if you want to debug a specific variable ($sArticle} in this example).

    You have to known that shopware assigns the members of an object to the view.