如何使用TWIG提取单词的首字母?

问题描述

在Drupal的8个视图中,我有一个带有令牌的字段。

如何使用TWIG提取单词的第一个字母?

我只想在此字段中显示令牌的首字母。

enter image description here

我测试了以下代码,但不起作用:

{{ '{{ name }}'|first }}

解决方法

尝试:

{{ name|first }}

{{ name|slice(0,1) }}

Twig: How to get the first character in a string