Questions about symfony passed values and asset in twig

Source: Internet
Author: User
The symfony framework is used. I transfer two values from the background to twig, and then want to assign values to asset (). What should I do? The Code passed by the Controller is as follows: {code ...} the twig code is as follows: {code ...} I know that the above method is not feasible, then define ImagePath and paginatio... the symfony framework is used. I transfer two values from the background to twig, and then want to assign values to asset (). What should I do? The code for the Controller to pass the value is as follows:

return $this->render("AcmeMinsuBundle:Default:advsImage.html.twig",                array('pagination' => $pagination,'cfgImagePath' => $cfgImagePath)            );

The twig code is as follows:

{% for paginations in pagination  %}    
  
  
{% endfor %}

I know that the above method is not feasible. Then, the variables ImagePath and paginations. getAdvsImagePath are combined to form an image path. How can I transfer the value or write the code in twig to achieve this. At the beginning, I started to use symfony, but I don't know much about it.

Reply content:

The symfony framework is used. I transfer two values from the background to twig, and then want to assign values to asset (). What should I do? The code for the Controller to pass the value is as follows:

return $this->render("AcmeMinsuBundle:Default:advsImage.html.twig",                array('pagination' => $pagination,'cfgImagePath' => $cfgImagePath)            );

The twig code is as follows:

{% for paginations in pagination  %}    
  
  
{% endfor %}

I know that the above method is not feasible. Then, the variables ImagePath and paginations. getAdvsImagePath are combined to form an image path. How can I transfer the value or write the code in twig to achieve this. At the beginning, I started to use symfony, but I don't know much about it.

Short answer: You need to use"~"Operator (see Twig documentation) Long answer:

You need to change the image label to the following:

Explanation:

  1. "{{ }}"Cannot be nested

  2. Connect two or more variables and strings, and use"~"Operator, equivalent to PHP"."Operator

  3. assetYestwigThe input variable is used by the function, rather than HTML. No quotation marks are provided here.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.