symfony - Twig 文件中两个变量的除法。

标签 symfony twig

我在 Twig 文件中有以下两个变量。

{%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%}

当我要划分这个得到这个错误时:
An exception has been thrown during the rendering of a template ("Notice: Object of class Twig_Markup could not be converted to int...

我需要得到这样的百分比
{{ (sanstha_actual/sanstha_target)*100}}

最佳答案

我认为你必须使用两个斜线,即

{{ (sanstha_actual // sanstha_target) * 100 }}

documentation 所示:

//: Divides two numbers and returns the floored integer result. {{ 20 // 7 }} is 2

关于symfony - Twig 文件中两个变量的除法。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23760183/

相关文章:

php - 是否可以在不删除数据库的情况下加载学说固定装置

javascript - 当我使用参数直接访问 url 时,AngularJS html5mode = true 错误

javascript - Symfony 导入 jquery 和 js 脚本

Twig 变量中的 Twig 变量

php - 如何在 Slim 3.5 中为 Twig 添加全局变量?

php - 如何使用 Symfony 在 Twig 中启用自动转义

php - PHP 文件中的 Symfony2 数据库配置

symfony - 是否可以在 Twig 中创建一个对象?

php - Symfony:获取现有表单引用

drupal - 如何在 Drupal 8 Twig 模板中使用图像样式?