Website/Blog about free and open source projects!
Specialty: Drupal, LibreOffice/OpenOffice.org, Linux/Unix, GPL.

Adding HTML tags in the <head> in Drupal 8 with a module

Step 1
Create a MODULNAME.libraries.yml file with: dependencies: - core/drupalSettings"!

MODULNAME:
version: VERSION
dependencies:
- core/drupalSettings
- core/drupal

Step 2
Add this hook_page_attachments() function in your module (MODULNAME.module):

/**
* Implements hook_page_attachments().
*/
function textsize_page_attachments(array &$page) {
$description = [
'#tag' => 'script',
'#attributes' => [

Zwahlendesign:

Add a class to the <body> in Drupal 8 with a module

Step 1

Create a MODULNAME.libraries.yml file with: dependencies: - core/drupalSettings"!


MODULNAME:
version: VERSION
dependencies:
- core/drupalSettings
- core/drupal

Step 2

Add this hook_preprocess_html() function in your module (MODULNAME.module):


/**
* Implements hook_preprocess_html().
*/
function MODULNAME_preprocess_html(&$variables) {
$variables['attributes']['class'][] = "BODYCLASS";
}

Zwahlendesign:

Programmer's Guide to Drupal

Book tip: Programmer's Guide to Drupal, 2nd Edition!
By Jennifer Hodgdon
Publisher: O'Reilly
Website: http://shop.oreilly.com/product/0636920034612.do
ISBN 978-1-4919-1146-4

Zwahlendesign:

Pages

Subscribe to ZwahlenDesign RSS