Drupal 8 - Theme building tips.

To remove existing css from the theme. (eg : css from core)

In THEME_NAME_info.yml

stylesheets-remove : 
  - core/modules/system/css/system.module.css
  - core/modules/views/css/views.module.css
 

Add some JS / CSS only for front-page : 

First create a new library in your THEME_NAME_library.yml


front-page-library:
    js:
      - js/bx-slider.js


Then add that library to page through a pre-processor (THEME_NAME.theme) :

<?php
function THEME_NAME_preprocess_page(&$variables) {
  if ($variables['is_front']) {
    $variables['#attached']['library'][] = 'THEME_NAME/front-page-library';
  }
}

The Home page should have the required `bx-slider.js` now.


More tips  coming up...






Comments

Popular posts from this blog

Filtering and Sorting a Doctrine Arraycollection

Doctrine mapping (ORM) with Database (DAL), Unidirectional vs Bidirectional.

Drupal 7 - How to make dynamic select box through Drupal #ajax framework