首页 > 解决方案 > TWIG:从字符串中修剪两个字符

问题描述

标签: phptwigtwig-filter

解决方案


Use php str_replace

str_replace([",", "₹"], "", $str);

replace for twig

{% if foo |replace({'₹':'', ',':''}) |number_format > 3000 %}

https://twig.symfony.com/doc/2.x/filters/replace.html

So how you would ideally do it would be pass in just a regular integer to your twig template, do the comparison & then if you need to display the whole string on the page, prefix the number_format to get the comma and if you wish decimal places.

https://twig.symfony.com/doc/2.x/filters/number_format.html


推荐阅读