Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shopware 5 accessing controller variables (Template Variables) on frontend

Tags:

shopware

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.

like image 222
Chathuraka Avatar asked Sep 19 '25 10:09

Chathuraka


2 Answers

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.

like image 192
Roman Avatar answered Sep 23 '25 13:09

Roman


Using the {debug} function will usually give you a list of all assigned variables. This list should also include a variable $Controller which will give you a hint to the currently related Controller.

Unfortunately you are not able to identify where the assigned variables come from. Due to the event driven architecture of Shopware the variables can be assigned to the view after the request has been dispatched to the related Controller. This means that variables might he assigned through third party plugins as well as specific event listeners and store front decorators (in Shopware 5).

Kind regards!

like image 28
barbieswimcrew Avatar answered Sep 23 '25 14:09

barbieswimcrew