drupal-8 - Drupal 8 Attached library to a paragraph
问题描述
How can I attached a library to an specific paragraph? This is what I have so far.
function THEME_preprocess_paragraph(&$variables){
$paragraph = $variables['paragraph'];
$parentBundle = $paragraph->getParentEntity()->bundle();
}
解决方案
如果您仍在寻找答案,您可以通过 twig 轻松完成此操作。只需为每个段落创建一个树枝模板,然后添加:{{ attach_library('theme/library') }}
.
您也可以通过您的 .theme 文件来执行此操作,但这对于您的需要可能是多余的。
推荐阅读
- python - 如何仅在 numpy 数组的“一维”上应用 K-means++ 并按原样保留另一维
- python - 基于 Keras LSTM 的神经网络不学习
- elixir - 如何在 Elixir 中展平嵌套列表?
- android - 如何在android的表格布局中删除选定的行
- javascript - Google Apps 脚本解析 .txt 文件并将内容插入工作表?
- kubernetes-helm - 从值生成发布名称
- python - 如果python中的行总和为零,则用字符串替换单元格
- karate - 我正在尝试复制具有的 csv 文件的导入;作为空手道中的分隔符,但好像该工具不认为这是有效的
- android - 在 EditText 字段中键入时如何清除错误?
- python - 无法为一维数据绘制 K-Means 聚类