N
N
Nikita Kolesnikov2018-10-29 00:37:44
Twig
Nikita Kolesnikov, 2018-10-29 00:37:44

How to add custom function to twig?

How can I create a function for twig that can pass parameters?
For example, in the template: {{ phrase('save') }}
And in the code, this function will be like this:

function phrase ($pharse_data) {
    ...
}

I don't quite understand how to implement this.
PS: do not hit hard with slippers

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
voronkovich, 2018-10-29
@NikitOS_MV

You need to create an extension for Twig and implement the function there. See https://twig.symfony.com/doc/2.x/advanced.html#id2

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question