Download the PHP package parisek/twig-attribute without Composer

On this page you can find all versions of the php package parisek/twig-attribute. 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-attribute

parisek/twig-attribute

Packagist Version PHP Version Tests Twig

A Twig 3 extension that gives templates a create_attribute() function for collecting, sanitizing, and rendering HTML attributes. It is backed by a vendored port of Drupal's Attribute class.

The package ships its own port (under Drupal\Component\Attribute) and does not depend on Drupal core. The maintainer refreshes the vendored sources from Drupal 11.x when upstream changes. The API matches what Drupal templates expect. One deliberate difference: this package rejects unsafe attribute names.

Installation

Requires PHP ^8.3 and Twig ^3.27. No Drupal dependencies.

Usage

Plain PHP:

Symfony service:

Timber 2 (WordPress). Timber creates the Twig environment itself, so do not build your own. Add the extension with the timber/twig filter, for example in your theme's functions.php:

parisek/timber-kit already registers the extension in its StarterBase. If you use the kit, you need no extra code.

In templates

create_attribute() and without register the safe class by themselves. Under Twig autoescape, call AttributeExtension::registerSafeClass($twig) once after addExtension() as well. Without it, a collection that prints before the first such call prints as " text. A subclass of AttributeCollection, or another MarkupInterface class, that Twig already escaped stays escaped. See Autoescape.

Filters

without returns a copy of an attribute collection (or a plain array) without the named keys. It never changes the original. Pass one name, several names or a list.

Unknown names are ignored. The behavior matches Drupal's without filter.

The filter itself is not marked safe. A collection prints as HTML only after registerSafeClass() ran (see Autoescape).

Attribute names

A name is checked when the attribute is created: in the constructor, setAttribute(), array access and create_attribute({...}). A name that is empty or contains ASCII whitespace, a control character (NUL included) or any of " ' < > / = throws an \InvalidArgumentException. Without the check, a name such as x onmouseover would render as two attributes.

Names for Alpine, Vue and Angular stay valid: @click, :class, x-on:click.prevent, [hidden], (click), *ngIf, #ref. Drupal does not check names, so this is a deliberate difference. Values are escaped as in Drupal.

Autoescape

With Twig autoescape on (for example 'autoescape' => 'html'), register the safe class once, right after you add the extension:

The call is safe to repeat. Call it before anything is rendered. It tells the Twig escaper that objects implementing the package's MarkupInterface are HTML. Strings, other Stringable values and arrays stay escaped.

Timber 2 turns autoescape off by default. A Timber theme, including one that uses parisek/timber-kit, needs nothing.

What to know:

The full API (class methods, escape semantics, without filter behavior) mirrors Drupal's Attribute class.

Development

The vendored Drupal port comes from Drupal 11.x core at git.drupalcode.org/project/drupal/-/tree/11.x/core/lib/Drupal/Core/Template.

A weekly workflow (upstream-watch) compares the vendored classes with upstream and opens an issue when they differ or when a security advisory (SA-CORE) commit appears. Run the same check by hand:

When upstream changes, copy the relevant files into .upstream/ (a gitignored scratch directory) and port them again. AGENTS.md describes the refresh steps, the inline shims that let the package drop drupal/core-render and drupal/core-utility, and the deliberate differences from Drupal.

Use cases


All versions of twig-attribute with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
twig/twig Version ^3.27
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 parisek/twig-attribute contains the following files

Loading the files please wait ...