Jacek Dziurdzikowski
Jacek Dziurdzikowski

Reputation: 2265

How to use Twig global parameter inside Twig function

I'm trying to use twig parameter I defined in config.yml:

twig:
    globals:
        my_path: "my_path"

in twig function asset() to concatenate "my_path" with the rest part of a path.

I tried:

src="{{ asset( my_path . 'the_rest_part_of_a_path') }}"

and even:

src="{{ asset( {{my_path}} . 'the_rest_part_of_a_path') }}"

Both are not working.

Is there any way I can use twig global parameter in that scenario?

Or maybe I can use symfony parameter defined in parameters.yml in such way?

Upvotes: 0

Views: 184

Answers (1)

xate
xate

Reputation: 6379

Twig uses ~ for string concatenation thus your example should be:

src="{{ asset(my_path ~ 'other_path') }}"

From the docs

~: Converts all operands into strings and concatenates them. {{ "Hello " ~ name ~ "!" }} would return (assuming name is 'John') Hello John!.

Upvotes: 3

Related Questions