Skip to main content
Drupal is a registered trademark of Dries Buytaert
Release: OpenID Connect / OAuth client 3.0.0-alpha9 New alpha version released for module openid_connect (3.0.0-alpha9). Usage Milestone: Google Analytics Module google_analytics crossed 1,000 active installs. Release: Timelinr 1.0.1 Minor update available for module timelinr (1.0.1). Release: GraphQL Compose Codegen 1.1.2 Minor update available for module graphql_compose_codegen (1.1.2). Release: Mapy.com 1.1.3 Minor update available for module mapycom (1.1.3). Release: Ckeditor5 entity browser 3.0.3 Minor update available for module ckeditor5_entity_browser (3.0.3). Release: Ckeditor5 entity browser 3.0.1 Minor update available for module ckeditor5_entity_browser (3.0.1). Release: Ckeditor5 entity browser 3.0.2 Minor update available for module ckeditor5_entity_browser (3.0.2). Release: Teamleader Integration 4.0.2 Minor update available for module teamleader (4.0.2). Module Revived: Entityqueue Buttons 1.1.2 Module entityqueue_buttons updated after 8 months of inactivity (1.1.2).

Attach Inline

192 sites Security covered Drupal 10–11
View on drupal.org

This module allows developers to attach inline JavaScript and CSS directly to render array elements within Drupal. It also enhances security by automatically adding hashes for Content Security Policy, helping to prevent XSS vulnerabilities.

Inline JavaScript should be re-rewritten to define libraries and use drupalSettings to pass data.

When inline code blocks are absolutely necessary, this module extends Drupal's asset system to allow attaching inline scripts and styles to render array elements so that they are added to the document's head after library script files.

When using Content Security Policy module, hashes are automatically added to the page's policy to remove the need for 'unsafe-inline', and limit the risk of Cross Site Scripting vulnerabilities.

Example Usage

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

    // New functionality
    'js' => [
      [
        'data' => 'alert("Hi!")',
        'scope' => 'header',
        'dependencies' => ['core/jquery'],
      ],
    ],
    'css' => [
      [
        'data' => '#logo { border 1px solid #000; }',
        'attributes' => [
          'media' => 'all',
        ]
        'group' => CSS_THEME,
      ],
    ],
  ],
];

Depends on

Dependencies of the latest stable release

No dependencies recorded for this project.

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
3
Tracked since
May 2025
Latest release
1 week ago
Releases (12 mo)
2 ▲ from 1
Maintenance
Active

Release Timeline

Releases

Version Type Core Release date
8.x-1.9 Stable 10–11 Aug 24, 2026
8.x-1.8 Stable 10–11 Jul 6, 2026
8.x-1.7 Stable 10–11 May 6, 2025