replace

这个 replace 通过替换占位符筛选给定字符串的格式(占位符是自由格式):

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
{{ "I like %this% and %that%."|replace({'%this%': foo, '%that%': "bar"}) }}

{# outputs I like foo and bar
   if the foo parameter equals to the foo string. #}

{# using % as a delimiter is purely conventional and optional #}

{{ "I like this and --that--."|replace({'this': foo, '--that--': "bar"}) }}

{# outputs I like foo and bar #}

争论

  • from :占位符值

参见

format