I have the following two variables in twig file.
{%set sanstha_target%}
{%render 'FrontBundle:Datasheet:getCurrentTarget' with {'dealer':recent_entry.id,'month':recent_entry.year~recent_entry.month,'type':'3'}%}
{%endset%}
{%set sanstha_actual%}
{%render 'FrontBundle:Datasheet:getTotal' with {'datasheet':recent_entry.datasheet,'dealer':recent_entry.id,'type':'3'}%}
{%endset%}
The when I am going to divide this getting this error:
An exception has been thrown during the rendering of a template ("Notice: Object of class Twig_Markup could not be converted to int...
I need to get the percentage like this
{{ (sanstha_actual/sanstha_target)*100}}
Twig != is a comparison operator. You can use != to compare any two things that php lets you compare, and what you get back is a boolean.
I think you have to use two slashes, i.e.
{{ (sanstha_actual // sanstha_target) * 100 }}
as shown in the documentation:
//: Divides two numbers and returns the floored integer result. {{ 20 // 7 }} is 2
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