在 TWIG 中使用 PHP 函数?函数、TWIG、PHP

2023-09-06 23:49:56 作者:梦境-Story

在 PHP 模板中我可以使用 php 函数,例如:

In PHP templates I can use php functions, for example:

foreach ($users as $user){
  echo someFunction($user->getName());
}

如何在 TWIG 中制作它?

How can I make it in TWIG?

{% for user in users %}
    * {{ user.name }}
{% else %}
    No user have been found.
{% endfor %}

我如何做到这一点?

推荐答案

你需要的是函数或 过滤器.您可以使用示例轻松添加这些内容.

What you need are functions or filters. You can easily add these using the examples.