Drupal 8 附加库到一个段落
Drupal 8 Attached library to a paragraph
如何将库附加到特定段落?这是我到目前为止所拥有的。
function THEME_preprocess_paragraph(&$variables){
$paragraph = $variables['paragraph'];
$parentBundle = $paragraph->getParentEntity()->bundle();
}
如果您仍在寻找答案,可以通过 twig 轻松完成。只需为每个段落创建一个树枝模板,然后添加:{{ attach_library('theme/library') }}
.
您也可以通过您的 .theme 文件执行此操作,但这对于您的需要来说可能有点过头了。
如何将库附加到特定段落?这是我到目前为止所拥有的。
function THEME_preprocess_paragraph(&$variables){
$paragraph = $variables['paragraph'];
$parentBundle = $paragraph->getParentEntity()->bundle();
}
如果您仍在寻找答案,可以通过 twig 轻松完成。只需为每个段落创建一个树枝模板,然后添加:{{ attach_library('theme/library') }}
.
您也可以通过您的 .theme 文件执行此操作,但这对于您的需要来说可能有点过头了。