如何在Drupal 8上的TWIG中以纯文本显示节点的标题?

问题描述 投票:1回答:1

我为我的节点,我的产品,我的团队和我的商店创建了TWIG。

我在Drupal 8上。对于我的节点,我想显示标题。我使用以下代码:

{{ label }}

但内部有标记,我不想要它。所以我尝试了以下代码,它的工作原理。但这是一个好习惯吗?

{{ label.0 }}

如何在Drupal 8上的TWIG中以纯文本显示节点的标题?

tags twig drupal-8 markup
1个回答
0
投票

当使用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. 

如该注释中所述,可以使用以下命令在树枝中访问没有任何标记的节点标题的值:

{{ node.label }}

© www.soinside.com 2019 - 2024. All rights reserved.