Drupal 8不会将html标签显示为字段值

问题描述

在mytheme.theme中,我找到了值:

$programmes = [];
$view = Views::getView('participating_programmes');
$view->execute();
foreach($view->result as $row){
    $nid = $row->_entity->get('nid')->getValue();
    $nid = $nid[0]['value'];
$text = $row->_entity->get('field_copy_text')->getValue();    
$programmes[$nid]['text'] = $text[0]['value'];

然后将其输出到我的树枝中

{{ programme.text }}

我获得了带有所有标签的完整html:

<p>This is the <strong>copy </strong>text for the Music subject.</p> <p>This is a <em>second </em>line with a break.</p>

我不想剥离标签。我想将其显示为带有中断和样式的html输出

解决方法

您需要更改树枝文件以将HTML输出为:

{{ programme.text|raw }}