I have the class categroies
and class Products
.
In my repository i have function
getProducts($categoryid,$location)
I need to loop in twig template like this
{% for category in categories %}
--{{ category.name }}--
{% for product in getProducts(category.id,location) %}
--{{ product.name }}--
{% endfor %}
{% endfor %}
or is there any better way for that
In Twig templates variables can be accessed using double curly braces notation {{ variableName }} .
You can get the current URL in Twig/Silex 2 like this: global. request. attributes. get('_route') .
You shouldn't. Thats business logic, that should not appear in templates. One solution is to create a new action within a controller and in your template call
{% render '@MyBundle:Product:list' with {category: category.id} %}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With