I need to attach js in all nodes with a specif paragraph bundle. I know how to do this with drupal_add_js, but I prefer don't use it to prevent cache problems.
I am trying with hook preprocess_entity but I don't get it, I don't know how to use the ["#attached"]
function THEME_preprocess_entity(&$variables) {
if (isset($variables['paragraphs_item']->bundle) && variables['paragraphs_item']->bundle == "XXXXX") {
$variables["elements"]["#attached"]['js'][] = array(
'type' => 'file',
'data' => 'myfile.js',
);
}
}
What am I doing wrong?
I don't know how to use the ["#attached"]
did you refer to the Drupal 7 documentation on this?