Download the PHP package alan-221b/twig_deluxe without Composer

On this page you can find all versions of the php package alan-221b/twig_deluxe. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package twig_deluxe

Twig Deluxe

Scoped CSS and JavaScript for Drupal Twig templates, inspired by Vue and Svelte single-file components.

Overview

Twig Deluxe brings component-scoped styles and scripts to Drupal theming. Write <style> and <script> tags inside {% scoped %}...{% endscoped %} blocks directly in your .html.twig files. At build time, the module extracts these into individual chunk files and automatically scopes CSS rules to the template using data-twig-scoped attributes on root HTML elements.

The result: styles defined in a template only affect that template's markup, with no global leakage. JavaScript is wrapped in Drupal behaviors and loaded on demand, only for pages that render the template.

This is a compile-time tool. The drush twig_deluxe:compile command processes your templates and writes chunk files to your theme directory. Your theme's asset pipeline (Vite or similar) then picks them up during the normal build.

Requirements

Installation

Usage

Place a {% scoped %} block anywhere in a .html.twig file. The block can contain a <style> tag, a <script> tag, or both.

CSS only

At compile time, the h2 and .my-component rules are rewritten to include the template's scope hash, and the <div class="my-component"> root element receives a data-twig-scoped="HASH" attribute in the rendered HTML.

CSS and JavaScript

Twig variables in scoped blocks

Twig variables cannot be used inside {% scoped %} blocks. This is enforced at compile time. The contents of a scoped block are static — they are extracted before Twig renders the template.

If you need to pass dynamic values to your scoped script, use data-* attributes on the DOM element:

Theme Integration

After running drush twig_deluxe:compile, the module writes chunk files into your active theme. The theme must be set up to consume them.

The module auto-creates these directories in your theme:

CSS

Create a file at {theme}/twig-deluxe/generated.css with the following content:

Then import it from your theme's main stylesheet:

The @import-glob syntax requires a PostCSS plugin such as postcss-import combined with postcss-import-ext-glob, or Vite's glob import support via a plugin.

JavaScript

In your theme's entry point (main.ts or main.js), add the following to dynamically load JS chunks for any scoped elements present on the page:

This pattern uses Vite's import.meta.glob to statically analyze all chunk files at build time, then loads only the ones needed for the current page at runtime.

Drush Commands

drush twig_deluxe:compile

Alias: tdc

Scans all enabled modules and the active theme for .html.twig files, extracts {% scoped %} blocks, and writes CSS and JS chunk files to the active theme's twig-deluxe/chunks/ directory.

Run this command before your theme's asset build step in CI/CD pipelines. The typical order is:

  1. drush twig_deluxe:compile
  2. npm run build (or equivalent)

Chunk files are named by hash, so unchanged templates produce identical filenames and content. This makes the output safe to commit to version control.

How It Works

Each template gets a scope hash derived from its file path (MD5, first 8 characters). This hash is stable across runs as long as the file path doesn't change.

At compile time:

  1. The {% scoped %} block is parsed out of the template source.
  2. CSS rules are rewritten by prepending [data-twig-scoped~="HASH"] to every selector. For example, h2 { color: navy; } becomes [data-twig-scoped~="a3f9c1b2"] h2 { color: navy; }.
  3. The rewritten CSS is written to chunks/css/HASH.css.
  4. JavaScript is written as-is to chunks/js/HASH.js.
  5. The template's root HTML element (the outermost tag) is modified to include data-twig-scoped="HASH" as a Twig attribute.

The root pseudo-selector maps to the scoped element itself. root:hover becomes [data-twig-scoped~="HASH"]:hover, targeting the root element directly rather than a descendant.

Template Inheritance

When a child template extends a parent using {% extends %}, the child inherits the parent's scope hash. CSS defined in the parent's {% scoped %} block applies correctly to markup rendered by the child, because the data-twig-scoped attribute on the root element carries the parent's hash.

If both parent and child define {% scoped %} blocks, the root element will carry both hashes as a space-separated list: data-twig-scoped="PARENT_HASH CHILD_HASH". Both stylesheets apply.

Limitations

License

GPL-2.0-or-later. See LICENSE.


All versions of twig_deluxe with dependencies

PHP Build Version
Package Version
Requires drupal/core Version ^10 || ^11
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package alan-221b/twig_deluxe contains the following files

Loading the files please wait ...