php - 允许原始过滤器在树枝的块视图中处理标签变量
问题描述
我想要实现的是在我的标签元素上设置原始过滤器,这样如果用户决定在 CMS 中放置 HTML 标签,它就可以工作。当我尝试这样做时,它似乎没有做任何事情(它仍然刷新 HTML 标记)。我想知道标签变量是否由 Drupal 在 xxx.theme 中预处理?无论如何,如果你们对我如何允许这些
标签有任何想法,那将是最好的。
到目前为止,我尝试的是添加raw twig 标签。
{#
/**
* @file
* Default theme implementation to display a block.
*
* Available variables:
* - plugin_id: The ID of the block implementation.
* - label: The configured label of the block if visible.
* - configuration: A list of the block's configuration values.
* - label: The configured label for the block.
* - label_display: The display settings for the label.
* - provider: The module or other provider that provided this block plugin.
* - Block plugin specific settings will also be stored here.
* - content: The content of this block.
* - attributes: array of HTML attributes populated by modules, intended to
* be added to the main container tag of this template.
* - id: A valid HTML ID and guaranteed unique.
* - title_attributes: Same as attributes, except applied to the main title
* tag that appears in the template.
* - title_prefix: Additional output populated by modules, intended to be
* displayed in front of the main title tag that appears in the template.
* - title_suffix: Additional output populated by modules, intended to be
* displayed after the main title tag that appears in the template.
*
* @see template_preprocess_block()
*
* @ingroup themeable
*/
#}
<div{{ attributes }}>
{{ title_prefix }}
{% if label %}
<h2{{ title_attributes }}>{{ label | raw }}</h2>
{% endif %}
{{ title_suffix }}
{% block content %}
{{ content }}
{% endblock %}
</div>
解决方案
而不是写My Block <br> Title
write My Block [br] Title
。
之后,将以下函数放入YOUR_THEME.theme
:
/**
* Implements hook_preprocess_block()
* @param array $variables
*/
function modern_preprocess_block(&$variables) {
if ( !empty($variables['label']) ) {
$variables['label'] = str_replace('[br]', '<br>', $variables['label']);
}
}
Drupal 从title
/label
字段中去除 HTML 标签,以便我们可以自信地假设它是纯文本。因此,这是一个解决方法。
推荐阅读
- javascript - nodejs ejs将数组对象渲染到表中
- android - 是否可以在没有 Dagger 模块的情况下提供 DAO 或 Room 数据库
- python - 将编辑模式下的本地库包含到 environment.yml
- android - 传递给 DatePicker 时的 LocalDate 在 android 中显示错误的值
- javascript - 如何在 jason 中获取所有数组上的特定数据并在 javascript 中使用它
- r - Building my unaltered package suddenly fails: for Vignettes and 'arch = x64'
- python - K fold cross validation---KeyError: '[] not in index'
- python - 如何将字节数组或字节对象拆分为 16 位整数?
- angular - Missing "Access-Control-Allow-Origin" header after a POST request with a 302 response
- python - how to sort a queryset using django and htmx?