symfony - 奇怪的意外 "stylesheets"标记错误

标签 symfony twig

安装后MopaBootstrapBundle ,我在第 19 行的 app/Resources/views/app.html.twig 中得到了意外的“样式表”标签(期望在第 19 行附近定义的“块”标签的结束标签)。
以前没遇到过!这是config.yml :

imports:
    - { resource: parameters.yml }
    - { resource: security.yml }
    - { resource: services.yml }
    - { resource: "@AdminUserBundle/Resources/config/services.yml" }

# Put parameters here that don't need to change on each machine where the app is deployed
# http://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
    locale: en

sonata_block:
    default_contexts: [cms]
    blocks:
        # Enable the SonataAdminBundle block
        sonata.admin.block.admin_list:
            contexts:   [admin]

framework:
    #esi:             ~
    #translator:      { fallbacks: ["%locale%"] }
    secret:          "%secret%"
    router:
        resource: "%kernel.root_dir%/config/routing.yml"
        strict_requirements: ~
    form:            ~
    csrf_protection: ~
    validation:      { enable_annotations: true }
    #serializer:      { enable_annotations: true }
    templating:
        engines: ['twig']
        #assets_version: SomeVersionScheme
    default_locale:  "%locale%"
    trusted_hosts:   ~
    trusted_proxies: ~
    session:
        # handler_id set to null will use default session handler from php.ini
        handler_id:  ~
    fragments:       ~
    http_method_override: true
    translator:      ~

# Twig Configuration
twig:
    debug:            "%kernel.debug%"
    strict_variables: "%kernel.debug%"

# Doctrine Configuration
doctrine:
    dbal:
        driver:   pdo_mysql
        host:     "%database_host%"
        port:     "%database_port%"
        dbname:   "%database_name%"
        user:     "%database_user%"
        password: "%database_password%"
        charset:  UTF8
        # if using pdo_sqlite as your database driver:
        #   1. add the path in parameters.yml
        #     e.g. database_path: "%kernel.root_dir%/data/data.db3"
        #   2. Uncomment database_path in parameters.yml.dist
        #   3. Uncomment next line:
        #     path:     "%database_path%"

    orm:
        auto_generate_proxy_classes: "%kernel.debug%"
        naming_strategy: doctrine.orm.naming_strategy.underscore
        auto_mapping: true

# Swiftmailer Configuration
swiftmailer:
    transport: "%mailer_transport%"
    host:      "%mailer_host%"
    username:  "%mailer_user%"
    password:  "%mailer_password%"
    spool:     { type: memory }

fos_user:
    db_driver: orm # other valid values are 'mongodb', 'couchdb' and 'propel'
    firewall_name: main
    user_class: Admin\UserBundle\Entity\User
    group:
        group_class: Admin\UserBundle\Entity\UserGroup

mopa_bootstrap:
    form: ~  # Adds twig form theme  support
    menu: ~  # enables twig helpers for menu

这是 app.html.twig 文件:
{% from 'MopaBootstrapBundle::flash.html.twig' import session_flash %}

<!DOCTYPE html>

{% block html_tag %}
<html lang="{{ app.request.locale }}">
{% endblock html_tag %}

{% block head %}
    <head>
        <meta charset="{{ _charset }}" />
        {% block head_style %}
            {# Override this block to add your own files! #}
            {# To use this without less or sass use the base.html.twig template as your base
             # Be sure you understand whats going on: have a look into
             # https://github.com/phiamo/MopaBootstrapBundle/blob/master/Resources/doc/css-vs-less.md
             #}
            {% block stylesheets %}
                {% stylesheets filter='cssrewrite'
                 '@MopaBootstrapBundle/Resources/public/bootstrap/dist/css/bootstrap.min.css'
                %}
            {% endblock stylesheets %}
        {% endblock head_style %}

        <meta name="viewport" content="width=device-width, initial-scale=1.0">

        {% block head_script %}
            {% block content_head_script %}{% endblock %}

        {% endblock head_script %}

        <title>{% block title %}Page{% endblock title %} - Mr.A</title>
        {% block favicon %}<link rel="shortcut icon" href="{{ asset('favicon.ico') }}" />{% endblock %}
        {% block head_bottom %}
        {% endblock head_bottom %}
    </head>
{% endblock head %}

{% block body_tag %}
<body dir="rtl">
{% endblock body_tag %}

{% block body_start %}
{% endblock body_start %}

{% block body %}
{% block navbar %}
    <nav class="navbar navbar-default navbar-fixed-top">
        <div class="container-fluid">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
            </div>
            <div id="navbar" class="navbar-collapse collapse">
                {{ mopa_bootstrap_menu('AdminAdminBundle:MainMenu:mainMenu', {'automenu': 'navbar'}) }}
            </div><!--/.nav-collapse -->
        </div><!--/.container-fluid -->
    </nav>
{% endblock navbar %}

{% block container %}
{% block container_div_start %}<div class="{% block container_class %}container-fluid{% endblock container_class %}">{% endblock container_div_start %}
    {% block header %}
        <div dir="rtl" class="page-header">
            <h1>فروشگاه آقای الف</h1>
        </div>
    {% endblock header %}

{% block content_div_start %}<div class="content">{% endblock content_div_start %}
    {% block flashes %}
        {% if app.session.flashbag.peekAll|length > 0 %}
            <div class="row">
                <div class="col-sm-12">
                    {{ session_flash() }}
                </div>
            </div>
        {% endif %}
    {% endblock flashes %}

    {% block content %}
    {% endblock content %}

{% block content_div_end %}</div>{% endblock content_div_end %}

{% block footer_tag_start %}
    <footer>
{% endblock footer_tag_start %}

    {% block footer %}
        <p>&copy; <a href="http://www.mrappleid.com" target="_blank">Mr.Apple&trade;</a> & <a href="http://www.saidi27.com">A.Saidi</a> 2014-2015</p>
        <p dir="rtl">این وب‌سایت با لیسانس <a href="http://opensource.org/licenses/mit-license.php">MIT</a> عرضه شده است.</p>
    {% endblock footer %}

{% block footer_tag_end %}
    </footer>
{% endblock footer_tag_end %}
{% block container_div_end %}</div><!-- /container -->{% endblock container_div_end %}
{% endblock container %}

    {% block body_end_before_js %}
    {% endblock body_end_before_js %}

{% block foot_script %}
    {% block content_foot_script %}
    {% endblock content_foot_script %}
    {# To only use a subset or add more js overwrite and copy paste this block
    To speed up page loads save a copy of jQuery in your project and override this block to include the correct path
    Otherwise the regeneration is done on every load in dev more with use_controller: true
     #}
    {% block foot_script_assetic %}
        {# Please add the javascripts you need in your project #}
    {% endblock foot_script_assetic %}

    <script type="text/javascript">
        $(document).ready(function () {
            $('[data-toggle="tooltip"]').tooltip();
            $('[data-toggle="popover"]').popover();
        });
    </script>
{% endblock foot_script %}
{% endblock body %}

{% block body_end %}
{% endblock body_end %}
</body>
</html>

最佳答案

默认情况下,symfony 2.8 似乎没有附带 AsseticBundle。您需要手动安装它。

1) 安装

composer require symfony/assetic-bundle

2) 添加到 AppKernel.php
$bundles = array(
  [...]
  new Symfony\Bundle\AsseticBundle\AsseticBundle(),
  [...]
);

3) 添加到 config.yml
assetic:
    debug:          "%kernel.debug%"
    use_controller: false
    bundles:        [ ]
    filters:
        cssrewrite: ~

应该这样做。

关于symfony - 奇怪的意外 "stylesheets"标记错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34039842/

相关文章:

php - Symfony2 - HTTPS 连接的独立子域

docker - Docker:需要在symfony项目中保留文件夹

php - 如何在 TWIG 的宏中访问 _context 变量?

symfony - 使 Controller 只给模板一个值,而不渲染它 - Symfony2

php - 使用 WSSE 的身份验证提供程序

php - 跨客户端用户的用户身份验证

php - Symfony 中的 Doctrine 迁移

php - WordPress Timber 获取自定义帖子类型的帖子

php - Twig - 在选择选项中添加翻译

javascript - Symfony2 : JavaScript doesn't work on Prod environment