Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i access repository functions in twig template in symfony2

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

like image 806
Mirage Avatar asked Aug 01 '12 06:08

Mirage


People also ask

How do you use variables in Twig?

In Twig templates variables can be accessed using double curly braces notation {{ variableName }} .

How do you find the current route in Twig?

You can get the current URL in Twig/Silex 2 like this: global. request. attributes. get('_route') .


1 Answers

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} %}
like image 133
KingCrunch Avatar answered Sep 18 '22 20:09

KingCrunch