简体   繁体   English

将参数传递到Symfony2中的树枝视图

[英]Pass parameter to twig view in Symfony2

I have a twig page which I included a picture , this picture will be loaded from a folder ( uploads ) , but the name ( example.jpg ) is loaded from the database : 我有一个树枝页面,其中包含一张picture ,该图片将从folder uploadsuploads ),但是名称( example.jpg )是从database加载的:

<img src="{{ asset('uploads/example1.jpg') }}">

this works for me , but I want now that example1.jpg will be passed to the twig page : 这对我example1.jpg ,但是我现在想将example1.jpg传递到twig页面:

return $this->render('MyAppExampleBundle:Default:index.html.twig', array(
            'logo' => $logo)); //$logo = 'example1.jpg'

How I can do this? 我该怎么做?

I have tried <img src="{{ asset('uploads/{{logo}}') }}"> but this is illogic and doesn't work . 我已经尝试过<img src="{{ asset('uploads/{{logo}}') }}">但这是不合理的,无法正常工作。

Any help plz 任何帮助请

What about, 关于什么,

<img src="{{ asset('uploads/' ~ logo) }}"> 

{{ ... }} twig delimiters can't be nested. {{ ... }}树枝分隔符不能嵌套。 You should then use concatenation. 然后,您应该使用串联。

尝试{{ asset('uploads/' ~ logo) }}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM