Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Division of Two Variables in Twig file.

Tags:

twig

symfony

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}}
like image 741
Rakhitha Avatar asked May 20 '14 12:05

Rakhitha


People also ask

What is not equal in twig?

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.


1 Answers

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

like image 62
LeonardoALARCON Avatar answered Sep 20 '22 05:09

LeonardoALARCON