Contents
How do you call a macro in twig?
Calling a Twig Macro. To call this macro right from the template it’s in, we use our output tags and the _self prefix on the macro name. {{ _self.socialList(networks, “three-share”) }}. This will call the socialList macro, passing in the networks hash, and the class name of three-share.
When to use auto import in twig 2.11?
Auto-import is only available as of Twig 2.11. For older versions, import macros using the special _self variable for the template name: Before Twig 2.11, when you want to use a macro in another macro from the same file, you need to import it locally: The scoping rules described in this paragraph are implemented as of Twig 2.11.
How are macros similar to PHP functions in twig?
In Twig 2.11, usage of macros was simplified and other features were added to help you work with macros. in #3012 . Macros are similar to PHP functions because you can pass arguments to them and the contents generated inside the macro are returned to include them in the place where the macro is called.
Which is the documentation for Twig 2.x?
You are reading the documentation for Twig 2.x. Switch to the documentation for Twig 1.x . 3.x . Macros are comparable with functions in regular programming languages.
Can a macro parameter be replaced in a string?
Parameters are not replaced inside string constants, but you can use the ‘#’ preprocessing operator instead. When a macro parameter is used with a leading ‘#’, the preprocessor replaces it with the literal text of the actual argument, converted to a string constant.
How to translate strings in twig templates in Drupal?
To translate those install “User interface translation” extend and then you find “User interface translation” in cunfiguration. There is long list of strings but your strings should located in last section. after this visit the page in a language that is not Original language to have them picked up by Drupal.