我知道這是常見的一種,並經常詢問樹枝的問題,但我卡住,弄得禁用逃逸/ URL編碼在Twig_SimpleFunction
問題:功能輸出將被逃了出來,而不是/?some_var=value&maybe_another_var=another_value
我得到%2F%3Fsome_var%3Dvalue%26maybe_another_var%3Danother_value
這completelly毀了我的錨標籤
目標:我想防止 auto_urlencoding這一切發生的時間與我的自定義功能。
我用什麼:一個utilphp::util::add_query_arg()方法和一個自定義的樹枝,功能(Twig_SimpleFunction
)
我如何使用它:在代碼
$twig->addFunction(new \Twig_SimpleFunction('util_add_query_args',
function(){
return \utilphp\util::add_query_arg(func_get_args());
},
array('is_safe' => array('all')) //also tried array('html') but didn't worked
));
我如何使用它:在tempalte
<img src="//{{app_host_name}}/{{ other_url_segments}}{{ util_add_query_args({'fontStyle' : style } , data.query_string)}}">
這應該追加&fontStyle=value_from_variable
給定的查詢字符串,並將其返回爲是
data.query_string
- 可能已經包含像?some_var=value&maybe_another_var=another_value
一個querysting但它可以從一個請求到另一個不同。在某些情況下是空的,所以爲了得到有效查詢刺痛我必須使用util::add_query_arg()
,因爲它也包括這樣的情況下
沒有工作:
- 加入
|raw
到{{ util_add_query_args({'fontStyle' : style } , data.query_string) }}
- 加入
{% autoescape false %} <img src="//{{app_host_name}}/{{ other_url_segments}}{{ util_add_query_args({'fontStyle' : style } , data.query_string)}}"> {% endautoescape %}
什麼我錯唱?!如何解決這個問題呢?