Symfony2 desde 0: Plantilla base

Definiremos la plantilla base para nuestras vistas en el fichero app/Resources/views/plantilla.html.twig

En el definiremos algunos bloques, montaremos una navbar con Bootstrap, y el formulario de login.

<!DOCTYPE HTML>
<html lang="es">
    <head>
        <meta charset="utf8"/>
        <title>{% block title %} Blog en Symfony2 - victorroblesweb.es{% endblock %}</title>
        <!-- jQuery CDN -->
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
        <!-- Bootstrap CDN -->
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap-theme.min.css">
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
    </head>

    <body>
        <header>
            <nav class="navbar navbar-default">
                <div class="container-fluid">
                    <!-- Brand and toggle get grouped for better mobile display -->
                    <div class="navbar-header">
                        <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                            <span class="sr-only">Toggle navigation</span>
                            <span class="icon-bar"></span>
                            <span class="icon-bar"></span>
                            <span class="icon-bar"></span>
                        </button>
                        <a class="navbar-brand" href="{{path("home")}}">Blog con Symfony2</a>
                    </div>

                    <!-- Collect the nav links, forms, and other content for toggling -->
                    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                        <ul class="nav navbar-nav">
                            {%block categorias%}
                            <li class="active"><a href="#">Link <span class="sr-only">(current)</span></a></li>
                            <li><a href="#">Link</a></li>
                            {%endblock%}
                        </ul>
                        
                        <ul class="nav navbar-nav navbar-right">
                            {% if is_granted('ROLE_USUARIO') or is_granted('ROLE_ADMIN') %}
                            <li class="dropdown">
                                <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
                                        {{app.user.name}} {{app.user.surname}}      
                                     <span class="caret"></span></a>
                                <ul class="dropdown-menu" role="menu">
                                    <li><a href="{{path("new_post")}}">Nuevo post</a></li>
                                    <li class="divider"></li>
                                    <li><a href="{{path("logout")}}">Cerrar sesión</a></li>
                                </ul>
                            </li>
                            {%endif%}
                        </ul>
                    </div><!-- /.navbar-collapse -->
                </div><!-- /.container-fluid -->
            </nav>
        </header>

        <section class="content col-lg-9 col-md-9 col-sm-9 col-xs-9">
                {%block content %} Contenido vacio por defecto {%endblock%}
        </section>
        <sidebar class="sidebar col-lg-3 col-md-3 col-sm-3 col-xs-3">
                {%block identificate %} 
                    {% if is_granted('ROLE_USUARIO') or is_granted('ROLE_ADMIN') %} 
                        {#{dump(app.user)}#}
                    {% else %}
                        <h3>Identificate</h3>
                        <hr/>
                        {% for mensaje in app.session.flashbag().get('login') %}
                        <p class="info">{{ mensaje }}</p>
                        {% endfor %}
                        {% if error is defined %}
                                No estas identificado
                                {{error.message}}
                        {% endif %}  
                            <form method="post" action="{{path('login_check')}}">
                                <label>Email</label>
                                <input type="email" name="_username" value="" class="form-control"/>
                                
                                <br/>
                                <label>Contraseña</label>
                                <input type="password" name="_password" class="form-control"/>
                                
                                <br/>
                                <input type="submit" value="Entrar" class="btn btn-success"/>
                                <a href="{{path("registro")}}" class="btn btn-warning">Registrate aquí</a>
                            </form>
                    {% endif %}

                {%endblock%}
            </sidebar>   
        <div class="clearfix"></div>
        <footer>
        <hr/>
         &copy; victorroblesweb.es
        </footer>
        </body>
    </html>

    

Víctor Robles WEB

Autor: Victor

Desarrollador web - Formador online - Blogger

Compartir este post