1

How to remove the global library from specific page ?

I want to rearrange java script files.

1

You need to implement hook_page_attachments_alter().

| improve this answer | |
  • Okay , how to check for that specific page ? – Eman Shaaban Nov 12 '16 at 6:15
  • Here are some examples drupal.org/node/2274705 – ya.teck Nov 12 '16 at 7:02
  • Unfortunately this does not seem to work for routes defined in module.routes.yml? – Cristian Romanescu Apr 1 at 10:30
  • It doesn't matter. I just need to know the route name. – ya.teck Apr 1 at 16:26
1

Yes, it's very simple to use the Hook_page_attarchment_alter() Please see the following code it may help you.

    function modulename_page_attachments_alter(array &$attachments) {

    // Conditionally remove an asset.
    $current_path = \Drupal::service('path.current')->getPath();
    $result = \Drupal::service('path.alias_manager')->getAliasByPath($current_path);
    if ($result == "/<url slug>" ){
      if (in_array('<theme name>/global-styling', $attachments['#attached']['library'])) {
        $index = array_search('<theme name>/global-styling', $attachments['#attached']['library']);
        unset($attachments['#attached']['library'][$index]);
      }
    }

}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.