2

I have a Symfony 2.1 version with a controller that returns the total of points. I am rendering this in my twig template as follows:

{%render "AdminBundle:Reports:getExpiringPoints" with {'id':dealer.id}%}

This prints the total points. I need to check that value and print it if the rendering value is greater that 0.

Is it possible in Symfony 2.1?

2 Answers 2

4

i found that :

    {% set x %}
        {%render "AdminBundle:Reports:getExpiringPoints" with {'id':dealer.id}%}
    {% endset %}

{% if x> 0 %}
  //display
{% endif %}

and after you can use it. Tell me if it works

Sign up to request clarification or add additional context in comments.

Comments

0

You can check it directly in the controller or with twig :

{% if var > 0 %}
  //display
{% endif %}

Twig supports all of the standard logical operators ==, !=, <, >, >=, and <=.

4 Comments

This is Ok. I need to assign var to {%render "AdminBundle:Reports:getExpiringPoints" with {'id':dealer.id}%} How to assign this?
I'm not sure to understand what you want. You can assigned variable directly in twig : twig.sensiolabs.org/doc/tags/set.html
Yes. But rendering value can not assign directly like this {% set var = render "AdminBundle:Reports:getExpiringPoints" with {'id':dealer.id}%}
I think the bast way is to check it directly in method "Reports:getExpiringPoints", and to return nothing if you result is not greater than 0.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.