【问题标题】:Drupal 8 - Accessing _entity in content variable in template to print out contentDrupal 8 - 访问模板中内容变量中的 _entity 以打印出内容
【发布时间】:2015-11-19 18:31:21
【问题描述】:

我正在尝试逐个字段打印出一个视图,以便我可以将我的样式应用到它并自定义它的外观。

当我复制 views-view-unformatted--MY-TEMPLATE.html.twig 我可以在默认视图中看到这些变量:

{#
/**
 * @file
 * Default theme implementation to display a view of unformatted rows.
 *
 * Available variables:
 * - title: The title of this group of rows. May be empty.
 * - rows: A list of the view's row items.
 *   - attributes: The row's HTML attributes.
 *   - content: The row's content.
 * - view: The view object.
 * - default_row_class: A flag indicating whether default classes should be
 *   used on rows.
 *
 * @see template_preprocess_views_view_unformatted()
 *
 * @ingroup themeable
 */
#}

使用 {{ kint(content) }} 后,我可以看到我有一个 _entity 字段如图所示

但是我不知道如何打印出这些特定字段,甚至无法使用 Kint 找出如何将它们分开。我试过这样做:

{{ kint(content._entity) }}

无济于事,还有很多其他尝试打印出来的方法。

感谢任何帮助!

【问题讨论】:

  • 我通过使用不同的视图模板解决了我的问题,但我相信我应该能够做到这一点,所以我会保持这个问题的开放性。
  • 你试过 content.entity 吗?

标签: drupal twig drupal-8


【解决方案1】:

这可能是因为 Content._entity 是一个节点实体,而不是可以打印的可渲染数组。

【讨论】:

    猜你喜欢
    • 2018-08-15
    • 1970-01-01
    • 2011-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-25
    • 1970-01-01
    相关资源
    最近更新 更多