首页 > 解决方案 > 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();
}

标签: drupal-8

解决方案


如果您仍在寻找答案,您可以通过 twig 轻松完成此操作。只需为每个段落创建一个树枝模板,然后添加:{{ attach_library('theme/library') }}.

您也可以通过您的 .theme 文件来执行此操作,但这对于您的需要可能是多余的。


推荐阅读