Php 如何在Twig函数中使用Twig全局参数
我正在尝试使用config.yml中定义的细枝参数:Php 如何在Twig函数中使用Twig全局参数,php,symfony,twig,Php,Symfony,Twig,我正在尝试使用config.yml中定义的细枝参数: twig: globals: my_path: "my_path" 在twig函数asset()中,将“我的路径”与路径的其余部分连接起来 我试过: src="{{ asset( my_path . 'the_rest_part_of_a_path') }}" 甚至: src="{{ asset( {{my_path}} . 'the_rest_part_of_a_path') }}" 两者都不起作用 在这种情况
twig:
globals:
my_path: "my_path"
在twig函数asset()中,将“我的路径”与路径的其余部分连接起来
我试过:
src="{{ asset( my_path . 'the_rest_part_of_a_path') }}"
甚至:
src="{{ asset( {{my_path}} . 'the_rest_part_of_a_path') }}"
两者都不起作用
在这种情况下,我有没有办法使用twig全局参数
或者我可以使用parameters.yml中定义的symfony参数,方法如下?Twig使用~进行字符串连接,因此您的示例应该是:
src="{{ asset(my_path ~ 'other_path') }}"
从
~:将所有操作数转换为字符串并连接它们。{{“Hello”~name~“!”}}将返回(假设名称为“John”)你好,John
Twig使用~进行字符串连接,因此您的示例应该是:
src="{{ asset(my_path ~ 'other_path') }}"
从
~:将所有操作数转换为字符串并连接它们。{{“Hello”~name~“!”}}将返回(假设名称为“John”)你好,John
src=“{asset(my_path ~'other_path')}}”
未测试
用于字符串concat,而不是
@Xatenev将您的评论作为答案发布?@JacekDziurdzikowski我已经添加了我的评论作为答案。@martias感谢您的提醒。src=“{{asset(my_path ~'other_path')}”
未测试~
用于字符串concat,而不是
@Xatenev将您的评论作为答案发布?@JacekDziurdzikowski我添加了我的评论作为答案。@martias谢谢您的提醒。