douan8473 2013-03-13 05:00 采纳率: 100%
浏览 101
已采纳

在symfony 2.1.8中启用ESI时出现Twig语法错误

Ive attempted to add an ESI render with {'standalone': true} to one of my twig templates and am getting the TWIG syntax error of:

Unexpected token "punctuation" of value "," ("end of statement block" expected) in AccommMiddleBundle:Home:layout.html.twig at line 155

here is the relevant twig template block:

150 <div class="container">
151     <h1>{{ blog_articles.0.title }}</h1>
152     <a href="{{blog_articles.0.guid}}">Moose</a>
153 </div>
154 
155 {% render url('accomm_middle_home_recent_articles', {fred: 1}), {'standalone': true} %}
156 
157 {% set charity_url = "http://www.accommodation.com/charity" %}

Removing the , {'standalone': true} gets the template to render fine.

Im using Symfony 2.1.8 with a clean vendors and there seems to be no differences with the standard edition dependencies. Any ideas on how to debug this ?

thanks for any help

MikeB

p.s. here are my installed packages

AccomDotCom/AccomDotComRESTClientBundle 0.1               The RESTFul models for talking to the Accommodation.com privateapi (baghdadsquirrel) via symfony
behat/behat                             v2.4.5            Scenario-oriented BDD framework for PHP 5.3
behat/gherkin                           v2.2.9            Gherkin DSL parser for PHP 5.3
behat/mink                              v1.4.3            Web acceptance testing framework for PHP 5.3
behat/mink-browserkit-driver            v1.0.4            Symfony2 BrowserKit driver for Mink framework
behat/mink-extension                    v1.0.1            Mink extension for Behat
behat/mink-selenium2-driver             v1.0.5            Selenium2 (WebDriver) driver for Mink framework
behat/mink-zombie-driver                v1.0.3            Zombie.js driver for Mink framework
behat/symfony2-extension                v1.0.1            Symfony2 framework extension for Behat
doctrine/common                         2.3.0             Common Library for Doctrine projects
doctrine/dbal                           2.3.2             Database Abstraction Layer
doctrine/doctrine-bundle                v1.0.0            Symfony DoctrineBundle
doctrine/orm                            2.3.2             Object-Relational-Mapper for PHP
guzzle/guzzle                           v2.8.7            Guzzle is a PHP HTTP client library and framework for building RESTful web service clients
instaclick/php-webdriver                1.0.12            PHP WebDriver for Selenium 2
jms/aop-bundle                          1.0.0             Adds AOP capabilities to Symfony2
jms/cg                                  1.0.0             Toolset for generating PHP code
jms/di-extra-bundle                     1.1.1             Allows to configure dependency injection using annotations
jms/metadata                            1.1.1             Class/method/property metadata management in PHP
jms/security-extra-bundle               1.2.0             Enhances the Symfony2 Security Component by adding several new features
kriswallsmith/assetic                   v1.1.0-alpha4     Asset Management for PHP
monolog/monolog                         1.2.1             Logging for PHP 5.3
nelmio/esi-debug-bundle                 1.0.0             Shows you caching information around ESI requests for debugging purposes
sensio/distribution-bundle              v2.1.8            The base bundle for the Symfony Distributions
sensio/framework-extra-bundle           v2.1.8            This bundle provides a way to configure your controllers with annotations
sensio/generator-bundle                 v2.1.8            This bundle generates code for you
swiftmailer/swiftmailer                 v4.2.2            Swiftmailer, free feature-rich PHP mailer
symfony/assetic-bundle                  v2.1.2            Integrates Assetic into Symfony2
symfony/monolog-bundle                  v2.1.8            Symfony MonologBundle
symfony/swiftmailer-bundle              v2.1.8            Symfony SwiftmailerBundle
symfony/symfony                         v2.1.8            The Symfony PHP framework
twig/extensions                         dev-master v1.0.0 Common additional features for Twig that do not directly belong in core
twig/twig                               v1.12.2           Twig, the flexible, fast, and secure template language for PHP
vipsoft/jira-extension                  v1.0.9            Load features for Behat from Jira issues
  • 写回答

1条回答 默认 最新

  • doujing2497 2013-03-13 05:49
    关注

    In Symfony2.1, to adapt your render block to the correct notation, you need to

    • put your arguments between single quote ' : in this case you would have'fred': 1
    • Add the with{} statement even if it's empty:

    Which gives you:

    {% render url('accomm_middle_home_recent_articles', {'fred': 1})  with {}, {'standalone': true} %}
    

    Note: It looks like the with{} statement is absolutely needed in Symfony2.1, from this security release. However, Symfony might have changed this recently and I don't think it is needed in Symfony2.2 anymore.

    {# the with argument is needed but ignored #}

    And an example they provide with it:

    {% render url("path_to_controller_router", { 'param': 1 }) with {}, { 'standalone': true } %}
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?