Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strange Unexpected "stylesheets" tag error

Tags:

twig

symfony

After installing MopaBootstrapBundle, I'm getting Unexpected "stylesheets" tag (expecting closing tag for the "block" tag defined near line 19) in app/Resources/views/app.html.twig at line 19. Never faced it before! here is 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

and here is app.html.twig file:

{% 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>
like image 428
Aien Saidi Avatar asked Dec 02 '15 10:12

Aien Saidi


2 Answers

Seems like symfony 2.8 does not ship with AsseticBundle by default. You need to install it manually.

1) Install

composer require symfony/assetic-bundle

2) Add to AppKernel.php

$bundles = array(
  [...]
  new Symfony\Bundle\AsseticBundle\AsseticBundle(),
  [...]
);

3) Add to config.yml

assetic:
    debug:          "%kernel.debug%"
    use_controller: false
    bundles:        [ ]
    filters:
        cssrewrite: ~

That should do it.

like image 89
Claude Avatar answered Oct 18 '22 12:10

Claude


You forgot to close stylesheets tag as well.

{% block stylesheets %}
        {% stylesheets filter='cssrewrite'
            '@MopaBootstrapBundle/Resources/public/bootstrap/dist/css/bootstrap.min.css'%}
            {# These lines should be added#}   
            <link rel="stylesheet" href="{{ asset_url }}" />
        {% endstylesheets%}

{% endblock stylesheets %}
like image 2
Turdaliev Nursultan Avatar answered Oct 18 '22 14:10

Turdaliev Nursultan