2016-07-27 32 views
-2
{% image '@AppBundle/Resources/public/images/florida.png'%} 
    <img src="{{ asset_url }}" alt="Example" height="200" width="200"/> 
{% endimage %} 

我從我的樹枝文件中獲取此代碼。我想從文件位置加載一個名爲「florida.png」的圖像:「@ AppBundle/Resources/public/images/florida.png」。我想替換「@ AppBundle/Resources/public/images/florida.png」有一個字符串變量,並想知道我怎麼能做到這一點?任何幫助將是極大的幫助!如何用Twig中的變量替換字符串

+2

你試過分配的普通樹枝呢?' {%set some_var = asset_url%}' – Ziumin

+0

對於樹枝我很新,我想知道你能否給我一個這樣的例子嗎? –

+2

樹枝文檔提供了很多例子http://twig.sensiolabs.org/doc /tags/set.html – Ziumin

回答

0

這是你以後?

<img src="{{ asset('bundles/app/images/florida.png') }}" alt="Example" height="200" width="200"/> 
+0

是的,非常感謝這麼多人! –