routeMatch
Displaying 1 - 1 of 1How To Attach Library To A Specific Content Type
If you need to upload a library with a module during its operation, in Drupal it's called attaching file.
Attaching a library can be done in several ways depending on your needs.
Remember that the library is always registered by its module or theme name followed by the library name.
DrupalVIP technical notebook & support
Code Snippet
function rwcenter_page_attachments(array &$attachments) {
$attachments['#attached']['library'][] = 'rwcenter/content';
$node = \Drupal::routeMatch()->getParameter('node') ?? \Drupal::routeMatch()->getParameter('node_preview');
if (is_null($node)) {}
else {
if ($node->getType()=='rwcenter') {
$attachments['#attached']['library'][] = 'rwcenter/content';
}
}
}