Part of the Twig ecosystem · 43 projects
This module allows you to manipulate HTML markup within Twig templates using the DomQuery library. It provides functions to select, modify, and remove HTML elements directly within your Twig code.
Allow alter html markup from twig with DomQuery library.
Install
Module required install with composer because it depend on package DomQuery
composer require 'drupal/twig_domquery'
Usage
Use whole DomQuery object
- Requirement add custom settings to settings.php
$settings['twig_sandbox_whitelisted_classes'] = [
'Drupal\\Core\\Template\\Attribute',
'Rct567\\DomQuery\\DomQuery'
];
Example for remove div has class field-label:
{% set dom = domQuery(form|render) %}
{% set _ = dom.find('.field-label').remove() %}
{{ dom.getOuterHtml|raw }}
Use support twig function without add custom settings
{{ domQuery_replace(form|render, "p:last", "<p>Last Item</p>")|raw }}
{{ domQuery_addClass(form|render, "p:last", "last-item")|raw }}
{{ domQuery_removeClass(form|render, "p.list", "list")|raw }}
Ask your assistant about Twig DomQuery
Check compatibility with your Drupal and PHP version, maintenance and security coverage, from current release data. How it works
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.
More in the Twig ecosystem
Most installed first
Activity
Releases
| Version | Type | Core | PHP | Release date | |
|---|---|---|---|---|---|
| 2.0.1 | Stable | 9–10 | Dec 8, 2023 |