Guest User

Untitled

a guest
Apr 20th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. my-theme/js/my-script.js
  2.  
  3. my-library:
  4. js:
  5. js/my-script.js: {}
  6.  
  7. name: my-theme
  8. type: theme
  9. description: my theme
  10. package: other
  11. core: 8.x
  12. libraries:
  13. - my-theme/global-effects
  14. - my-theme/my-library
  15.  
  16. base theme: stable
  17.  
  18. function mytheme_page_attachments_alter(&$page){
  19. $path = $current_path = Drupal::service('path.current')->getPath();
  20. if($path == '/node') {
  21. $page['#attached']['library'][] = 'my-theme/my-library';
  22. }
  23. }
  24.  
  25. function mytheme_preprocess_page(&$variables){
  26. if ($variables['is_front'] == TRUE) {
  27. $variables['#attached']['library'][] = 'my-theme/my-library';
  28. }
  29. }
  30.  
  31. {% if node.id == 1 %}
  32. {{ attach_library('my-theme/my-library') }}
  33. {% endif %}
Add Comment
Please, Sign In to add comment