ML1*_*L19 3 tags markup twig drupal-8
我为我的节点、我的产品、我的群组和我的商店创建了 TWIG。
我在 Drupal 8 上。对于我的节点,我想显示标题。我使用以下代码:
{{ label }}
Run Code Online (Sandbox Code Playgroud)
但是里面有标记,我不想要它。所以我尝试了以下代码并且它有效。但这是一个好习惯吗?
{{ label.0 }}
Run Code Online (Sandbox Code Playgroud)
如何在 Drupal 8 上的 TWIG 中以纯文本形式显示节点的标题?
使用该node.html.twig模板的或 子模板时,您将可以访问该node变量,这是该node对象的有限实现。
来自经典主题node.html.twig文件的评论:
* - node: The node entity with limited access to object properties and methods.
* Only method names starting with "get", "has", or "is" and a few common
* methods such as "id", "label", and "bundle" are available. For example:
* - node.getCreatedTime() will return the node creation timestamp.
* - node.hasField('field_example') returns TRUE if the node bundle includes
* field_example. (This does not indicate the presence of a value in this
* field.)
* - node.isPublished() will return whether the node is published or not.
Run Code Online (Sandbox Code Playgroud)
正如该评论中所述,可以使用以下命令在 twig 中访问没有任何标记的节点标题的值:
{{ node.label }}.
| 归档时间: |
|
| 查看次数: |
3339 次 |
| 最近记录: |