Sylius Stack
  • Sylius Stack Documentation
  • Getting started
  • Cookbook
    • How to customize your admin panel
      • Basic operations
      • Customizing your grids
      • Customizing the logo
      • Customizing the menu
      • Configuring the security access
      • Customizing the page titles
    • How to use in a DDD architecture
      • Architecture overview
      • Resource configuration
      • Basic operations
      • Operation using a grid
  • Admin UI
    • Getting started
  • Bootstrap Admin UI
    • Getting started
  • Resource
    • Resource Bundle documentation
      • Installation
      • Create new resource
      • Configure your resource
      • Configure your operations
      • Validation
      • Redirect
      • Resource factories
      • Providers
      • Processors
      • Responders
      • Legacy Resource Documentation
        • Configuration
        • Services
        • Routing
        • Forms
        • Getting a Single Resource
        • Getting a Collection of Resources
        • Creating Resources
        • Updating Resources
        • Deleting Resources
        • Configuring a state machine
        • Configuration Reference
  • Grid
    • Grid Bundle documentation
      • Installation
      • Creating your first grid
      • Configuring Fields
      • Field types
      • Creating a custom Field Type
      • Creating a custom Action
      • Creating a custom Bulk Action
      • Filters
      • Creating a custom Filter
      • Advanced configuration
      • Configuration Reference
  • 🍀Twig Extra
    • Getting started
  • 🌱Twig Hooks
    • Getting started
    • Passing data to your hookables
    • Making your hookables configurable
    • Autoprefixing feature
    • Composable Layouts with a predictable structure
    • Advanced
      • Ergonomic work with hooks
      • Metadata objects
      • Multiple hooks inside a single template
      • Overriding hookables
Powered by GitBook
On this page
  1. Twig Hooks

Autoprefixing feature

PreviousMaking your hookables configurableNextComposable Layouts with a predictable structure

Last updated 4 months ago

Autoprefixing feature

Autoprefixing is turned off by default. If you want to use this feature you need to set the enable_autoprefixing setting to true in your config/packages/twig_hooks.yaml file:

sylius_twig_hooks:
    # ...
    enable_autoprefixing: true
    # ...

When you are creating a bundle, or a bigger project like , you might want to rely fully on Twig Hooks to provide easy and flexible way of modifying and extending your views.

Enabling the autoprefixing feature might improve your developer experience. This feature is crucial for creating Composable Layouts with a predictable structure.

If you did not read the Composable Layouts with a predictable structure section we encourage you to do it before you read more about the autoprefixing feature.

The mechanism of autoprefixing is pretty simple. We check if there are any prefixes, then we iterate over them and prepend the hook name with a given prefix.

Defining prefixes

Prefixes by default are injected automatically, and they are the name of the hook where the hookable is rendered.

As a developer I define the index.form hook in my template

And I define the some_field hookable in it

So when I check prefixes inside the some_field hookable I should get index.form

In case we deal with a complex hook:

As a developer I define the index.form, common.form hook in my template

And I define the some_field hookable in index.form

So when I check prefixes inside the some_field hookable I should get index.form and common.form

If for some reason you want to take the control over the passed prefixes, you can override existing prefixes using the _prefixes magic variable when you are creating a hook inside a Twig template:

index.html.twig
{% hook 'index.form' with {
    _prefixes: ['my_custom_prefix']
} %}

From now, only the value of _prefixes will be taken into account.

Example

index.html.twig
{% hook 'app.index' %}

{# index.html.twig is an entry template, so it is not an hookable #}
index/content.html.twig
{% hook 'content' %}

{# this template is an hookable, and is hooked into app.index #}

{#
 # so {% hook 'content' %} this is a shorter form of {% hook 'app.index.content' %}
 # when autoprefixing is turned on
 #}
index/content/button.html.twig
<button>Click me!</button>

The configuration for the hooks and hookables above is:

config/packages/twig_hooks.yaml
sylius_twig_hooks:
    hooks:
        'app.index':
            content:
                template: 'index/content.html.twig'

        'app.index.content':
            button:
                template: 'index/content/button.html.twig

The structure of directories above does not matter, all templates can be on the same level of nesting. However, in this example we are following creating Composable Layouts with a predictable structure guide.

🌱
Sylius