hook_page_attachments_alter(array &$attachments)
Alter attachments (typically assets) to a page before it is rendered.
Use this hook when you want to remove or alter attachments on the page, or add attachments to the page that depend on another module's attachments (this hook runs after hook_page_attachments().
If you try to add anything but #attached and #cache to the array, an exception is thrown.
Parameters
array &$attachments: Array of all attachments provided by hook_page_attachments() implementations.
See also
Related topics
- Hooks
- Define functions that alter the behavior of Drupal core.
File
- core/lib/Drupal/Core/Render/theme.api.php, line 1040
- Hooks and documentation related to the theme and render system.
Code
function hook_page_attachments_alter(array &$attachments) { // Conditionally remove an asset. if (in_array('core/jquery', $attachments['#attached']['library'])) { $index = array_search('core/jquery', $attachments['#attached']['library']); unset($attachments['#attached']['library'][$index]); } }
Please login to continue.