Skip to content

Latest commit

 

History

History
35 lines (32 loc) · 686 Bytes

readme.md

File metadata and controls

35 lines (32 loc) · 686 Bytes

Attach Inline

Add inline scripts and styles to a Drupal 8 site.

$render['element'] = [
  '#attached' => [
    // Existing Functionality
    'library' => [
      'drupal/drupalSettings'
    ],
    'drupalSettings' => ['module' => $data],

    // New functionality
    'js' => [
      [
        'data'   => 'alert("Hi!")',
        'scope'  => 'header',
        'group'  => JS_DEFAULT,
        'weight' => -30,
        'dependencies' => ['core/jquery'],
      ],
    ],
    'css' => [
      [
        'data'  => '.highlight { background-color: yellow; }',
        'group' => CSS_THEME,
        'attributes' => [
          'media' => 'all',
        ]
      ],
    ],
  ],
];