Skip to the content
Documentation
Help Start
Reading in:
  • German: 9,059 of 9,059 pages
About the help in other languages
All help pages

Twig components

What ibexa/twig-components adds to a DXP project - named groups of small components (script, stylesheet, template, controller, html, menu) configured in YAML and rendered with ibexa_twig_component_group - and how to use…

Download as PDF

Address: https://doc.exponential.earth/exphelp/viewer/help/dxp-developers/twig-components.md

On this page

Twig components

This page is for developers who want to add small pieces of output to places a template or bundle has prepared, without editing that template. The package ibexa/twig-components is part of the DXP metapackage. The facts below were read from its configuration class and the commented example the recipe writes to config/packages/ibexa_twig_components.yaml.

Contents

  1. The idea
  2. Component types
  3. Configuring a group
  4. Rendering
  5. Good use

The idea

A template renders a named group. Any bundle or your project can add components to that group. The group renders every component in order of priority. A layout can thus offer, for example, a "head" group where several packages add their stylesheet links.

Component types

TypeRenders
scriptA <script> element for a file
stylesheetA <link rel="stylesheet"> element
templateA Twig template with parameters
controllerThe output of a controller
htmlA fixed piece of HTML
menuA menu

Any other type is refused with "Invalid type ... Allowed types: ..." when the container is built.

Configuring a group

# config/packages/ibexa_twig_components.yaml
ibexa_twig_components:
    exp_site_head:                       # the group name
        exp_site_print_css:              # the component name
            type: stylesheet
            priority: 10
            arguments:
                href: '/assets/app/print.css'
        exp_site_notice:
            type: template
            arguments:
                template: '@ibexadesign/parts/notice.html.twig'

Each component needs type and arguments; priority defaults to 0. The arguments each type accepts are the constructor arguments of its component class under vendor/ibexa/twig-components/src/lib/Component/; read them before you configure one.

Rendering

<head>
    {{ ibexa_twig_component_group('exp_site_head') }}
</head>

ibexa_twig_component(...) renders a single component.

Good use

  • Prefer stylesheet, script and template components over html: inline markup in configuration is hard to review, and inline scripts and styles break a strict Content Security Policy.
  • Use exp_ group and component names for your own; never reuse a name a bundle defined unless you mean to add to its group.
  • After a change, clear the cache: the configuration is compiled into the container.

Become an Exponential Partner

Partners share their information, provide funding, contribute back and develop the products with us, and that is how Exponential grows. A partner website and dashboard are planned for mid-2027: please become a partner today to speed up our growth rate and land new features faster.

Something wrong on this page? Report an error

Documentation license

This documentation is free documentation, licensed under the GNU Free Documentation License 1.3 or later.

Exponential Copyright © 1998-2026 Exponential Foundation and 7x