php - Using Assetic on Twig embed -
im new symfony2 , twig, want adapt admin template twig , include in symfony2 project bundle.
i create bundle assets , templates , partials.
i solved many problems after working, don't understand why assetic not generating files.
i have next folders inside src/name/bundle/resources:
- public
- admin
- css
- global
- images
- js
- views
- default
- default.html.twig
- layouts
- login.html.twig
- partials
- footer.html.twig
- head.html.twig
- header.html.twig
- javascripts.html.twig
- sidebar.html.twig
- default
the idea define default layout, partials can include in future layouts, , generate different layouts extending default.html.twig , embedding assets css or js specific type of pages.
default.html.twig
<!doctype html> <!--[if ie 8]> <html lang="en" class="ie8"> <![endif]--> <!--[if ie 9]> <html lang="en" class="ie9"> <![endif]--> <!--[if !ie]><!--> <html lang="en"> <!--<![endif]--> <head> {% block head %}{% endblock %} </head> <body> {% block header %}{% endblock %} {% block sidebar %} {#{{ include('namebundle:partials:sidebar.html.twig') }}#} {% endblock %} {% block content %}{% endblock %} {% block footer %}{% endblock %} {% block javascripts %}{% endblock %} </body> </html>
head.html.twig
<meta charset="utf-8"/> <title>{% block title %}admin dashboard template{% endblock %}</title> <meta http-equiv="x-ua-compatible" content="ie=edge"> <meta content="width=device-width, initial-scale=1" name="viewport"/> <meta content="" name="description"/> <meta content="" name="author"/> {% block stylesheets %} <link href="http://fonts.googleapis.com/css?family=open+sans:400,300,600,700&subset=all" rel="stylesheet" type="text/css"/> <!-- begin global mandatory styles --> {% stylesheets '@namebundle/resources/public/global/plugins/font-awesome/css/font-awesome.min.css' '@namebundle/resources/public/global/plugins/simple-line-icons/simple-line-icons.min.css' '@namebundle/resources/public/global/plugins/bootstrap/css/bootstrap.min.css' '@namebundle/resources/public/global/plugins/uniform/css/uniform.default.css' %} <link href="{{ asset_url }}" rel="stylesheet" type="text/css"/> {% endstylesheets %} <!-- end global mandatory styles --> <!-- begin page level plugin styles --> {% block page_level_plugin_stylesheets %}{% endblock %} <!-- end page level plugin styles --> <!-- begin page styles --> {% block page_stylesheets %}{% endblock %} <!-- end page styles --> <!-- begin theme styles --> {% stylesheets '@namebundle/resources/public/global/css/components.css' '@namebundle/resources/public/global/css/plugins.css' '@namebundle/resources/public/admin/layout/css/layout.css' '@namebundle/resources/public/admin/layout/css/themes/default.css' '@namebundle/resources/public/admin/layout/css/custom.css' %} <link href="{{ asset_url }}" rel="stylesheet" type="text/css"/> {% endstylesheets %} <!-- end theme styles --> <link rel="shortcut icon" href="favicon.ico"/> {% endblock %}
i have 2 static fields, , want generate login template, extending default template , adding assets head:
login.html.twig
{% extends 'namebundle:default:metronic.html.twig' %} {% block head %} {% embed 'namebundle:partials:head.html.twig' %} {% block page_stylesheets %} {% stylesheets '@namebundle/resources/public/global/plugins/select2/select2.css' '@namebundle/resources/public/admin/pages/css/login.css' %} <link href="{{ asset_url }}" rel="stylesheet" type="text/css"/> {% endstylesheets %} {% endblock %} {% endembed %} {{ parent() }} {% endblock %}
config_dev.yml
assetic: use_controller: false bundles: [ d2armorymetronicbundle ]
also used:
php app/console assetic:dump --watch php app/console cache:clear
the result of code in browser is:
<head> <meta charset="utf-8"> <title>admin dashboard template</title> <meta http-equiv="x-ua-compatible" content="ie=edge"> <meta content="width=device-width, initial-scale=1" name="viewport"> <meta content="" name="description"> <meta content="" name="author"> <link href="http://fonts.googleapis.com/css?family=open+sans:400,300,600,700&subset=all" rel="stylesheet" type="text/css"> <!-- begin global mandatory styles --> <link href="/css/05f94b6_font-awesome.min_1.css" rel="stylesheet" type="text/css"> <link href="/css/05f94b6_simple-line-icons.min_2.css" rel="stylesheet" type="text/css"> <link href="/css/05f94b6_bootstrap.min_3.css" rel="stylesheet" type="text/css"> <link href="/css/05f94b6_uniform.default_4.css" rel="stylesheet" type="text/css"> <!-- end global mandatory styles --> <!-- begin page level plugin styles --> <!-- end page level plugin styles --> <!-- begin page styles --> <link href="/css/bf1faf2_select2_1.css" rel="stylesheet" type="text/css"> <link href="/css/bf1faf2_login_2.css" rel="stylesheet" type="text/css"> <!-- end page styles --> <!-- begin theme styles --> <link href="/css/ed78c26_components_1.css" rel="stylesheet" type="text/css"> <link href="/css/ed78c26_plugins_2.css" rel="stylesheet" type="text/css"> <link href="/css/ed78c26_layout_3.css" rel="stylesheet" type="text/css"> <link href="/css/ed78c26_default_4.css" rel="stylesheet" type="text/css"> <link href="/css/ed78c26_custom_5.css" rel="stylesheet" type="text/css"> <!-- end theme styles --> <link rel="shortcut icon" href="favicon.ico"> </head>
how controller on false value can see files created @ /web/css.
in head code can find 3 prefix assets:
05f94b6_ // files included in head.html.twig generated bf1faf2_ // files included in login.html.twig embed code not generated ed78c26_ // files included in head.html.twig generated
i don't know if forgive or misunderstand of workflow.
thanks in advance , sorry english, try give best.
Comments
Post a Comment