Twig

灵活、快速且安全的
PHP 模板引擎

a Symfony Product
文档 过滤器 replace
您正在阅读 Twig 3.x 的文档。切换到 Twig 1.x, 2.x 的文档。

问题与反馈

许可

Twig 文档 根据新 BSD 许可获得许可。

replace

The replace 过滤器替换字符串中的占位符(占位符格式是自由形式的)

1
2
3
4
5
6
7
{{ "I like %this% and %that%."|replace({'%this%': fruit, '%that%': "oranges"}) }}
{# if the "fruit" variable is set to "apples", #}
{# it outputs "I like apples and oranges" #}

{# using % as a delimiter is purely conventional and optional #}
{{ "I like this and --that--."|replace({'this': fruit, '--that--': "oranges"}) }}
{# outputs "I like apples and oranges" #}

参数

  • from: 作为映射的占位符值

参见

format