【问题标题】:Twig syntax error when enabling ESI in symfony 2.1.8在 symfony 2.1.8 中启用 ESI 时出现 Twig 语法错误
【发布时间】:2013-03-13 14:02:47
【问题描述】:

我尝试将带有 {'standalone': true} 的 ESI 渲染添加到我的一个树枝模板中,并收到以下 TWIG 语法错误:

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

这里是相关的树枝模板块:

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" %}

移除 , {'standalone': true} 让模板渲染得很好。

我使用 Symfony 2.1.8 和干净的供应商,似乎与标准版依赖项没有区别。关于如何调试的任何想法?

感谢您的帮助

迈克B

附言这是我安装的包

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

【问题讨论】:

    标签: php symfony twig symfony-2.1 esi


    【解决方案1】:

    Symfony2.1 中,要将渲染块调整为正确的符号,您需要

    • 把你的论点放在单引号 ' 之间:在这种情况下你会有'fred': 1
    • 添加with{} 语句即使它是空的

    这给了你:

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

    注意:看起来在 Symfony2.1 中绝对需要 with{} 语句,来自 security release。然而,Symfony 最近可能已经改变了这一点,我认为 Symfony2.2 不再需要它了。

    {# with 参数是必需的,但忽略了 #}

    还有一个他们提供的例子:

    {% render url("path_to_controller_router", { 'param': 1 }) with {}, { 'standalone': true } %}
    

    【讨论】:

    • 感谢 @Patt 使用来自 symfony http cache 的 doco,并且没有看到安全公告中包含 {}。现在回到我的头撞到我的清漆配置的砖墙上:)
    • 太棒了!如果您是该网站的新手,如果他们解决了您的问题,请不要忘记接受答案!祝 Varnish 好运。
    • 好吧,多年来一直在使用这个网站,但这是我的第一个问题 :).. 非常感谢您的提示。
    猜你喜欢
    • 1970-01-01
    • 2017-11-21
    • 2019-01-11
    • 2017-03-27
    • 1970-01-01
    • 1970-01-01
    • 2020-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多