沃梦达 / 编程问答 / php问题 / 正文

在 TWIG 中使用 PHP 函数?

Use PHP function in TWIG?(在 TWIG 中使用 PHP 函数?)

本文介绍了在 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 函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:在 TWIG 中使用 PHP 函数?