在 TWIG 中使用 PHP 函数? [英] Use PHP function in TWIG?

查看:18
本文介绍了在 TWIG 中使用 PHP 函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 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.

这篇关于在 TWIG 中使用 PHP 函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆