Autoprefixing feature
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:
When you are creating a bundle, or a bigger project like Sylius, 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
andcommon.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:
From now, only the value of _prefixes
will be taken into account.
Example
The configuration for the hooks and hookables above is:
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.
Last updated