Weitere ähnliche Inhalte Ähnlich wie Desymfony 2011 - Twig (20) Mehr von Javier Eguiluz (19) Kürzlich hochgeladen (11) Desymfony 2011 - Twig2. Patrocinadores Patrocinadores Patrocinadores
Colaboradores BRONCE PLATA PLATINO y ORO JORNADAS SYMFONY 2011 están patrocinadas por
3. importante
Algunas partes de esta presentación
no se pueden entender bien sin ver
el vídeo de su impartición.
Puedes acceder al vídeo en
http://bit.ly/sf-tutorial-twig
7. <mensaje>
Hola <p>Hola
<contenido>
{ nombre } Hola José
José</p>
...
... ......
... ...
</contenido>
</mensaje>
12. {* *} <%# %> {# #}
{ } <% %> {% %}
{$ } <%= %> {{ }}
13. {% if usuario is defined %}
Hola {{ usuario.nombre }}
hoy es {{ 'now' | date('d/m/Y') }}
{% endif %}
15. <p> Hola {{ usuario }}
Tienes {{ edad }} años y vives en
{{ ciudad }} </p>
16. <p> Hola {{ usuario.nombre }}
Tienes {{ usuario.edad }} años y
vives en {{ usuario.ciudad }} </p>
33. « Lo más poderoso
de Twig »
Fuente: documentación oficial de Twig
41. contacto.twig 2
{% extends "layout.twig" %}
{% block cuerpo %}
Duis aute irure dolor in ...
{% endblock %}
42. layout.twig 3
...
<h1>
{% block titulo %}
Lorem Ipsum
{% endblock %}
</h1>
...
44. 1. Muy fácil de aprender (intuitivo)
2. Suficiente / completo
3. Plantillas concisas y bonitas
47. {{ usuario.nombre }}
1. $usuario["nombre"]
2. $usuario!>nombre
3. $usuario!>nombre()
4. $usuario!>getNombre()
5. $usuario!>isNombre()
6. null
52. {% set perfil %}
{{ apellidos }}, {{ nombre }}
{{ edad }} años
Página: {{ url }}
{% endset %}
56. {{ descripcion }}
{{! descripcion }} ltrim(descripcion)
{{ descripcion !}} rtrim(descripcion)
{{! descripcion !}} trim(descripcion)
60. {{ articulo | truncate(150) }}
{{ articulo | truncate(150, true) }}
62. « Twig por defecto escapa
todas las variables »
67. Taversable
Countable
{
{% for articulo in articulos %}
...
{% endfor %}
68. {% for i in 0..10 %}
...
{% endfor %}
69. {% for i in 'a'..'z' %}
...
{% endfor %}
70. {% for articulo in articulos %}
...
{% else %}
No existen artículos
{% endfor %}
71. {% for . in . %} {% for . in . %}
... ...
{% empty %} {% else %}
... ...
{% endfor %} {% endfor %}
72. variables dentro del for
loop.index loop.revindex
loop.index0 loop.revindex0
loop.first
loop.parent
loop.last
loop.length
73. {% for articulo in articulos %}
articulo número {{ loop.index }}
{% endfor %}
74. {% for articulo in articulos %}
{% if not loop.first %}
Anterior
{% endif %}
{% if not loop.last %}
Siguiente
{% endif %}
{% endfor %}
75. {% for seccion in secciones %}
{% for categoria in categorias %}
{{ loop.parent.loop.index }}
{{ loop.index }}
{% endfor %}
{% endfor %}
79. {% if conectado %}
...
{% elseif registrado %}
...
{% else %}
...
{% endif %}
81. {% if texto is none %}
{% if numero is even %}
{% if numero is odd %}
82. {% if descripcion is empty %}
if (descripcion == null ||
descripcion == false ||
descripcion == "") {
...
}
90. <html>
<head>
layout.twig
<title>
{% block titulo %}{% endblock %}
</title>
</head>
<body>
<h1>
{% block titulo %}{% endblock %}
</h1>
91. <html>
<head> layout.twig
<title>
{% block titulo %}{% endblock %}
</title>
</head>
<body>
<h1>
{{ block('title') }}
</h1>
95. {% block contenidos %}
{% block principal %}
...
{% endblock principal %}
{% endblock contenidos %}
104. {% set articulos =
destacados | merge(otros) %}
{% include "listado.html"
with { 'items': articulos }
only %}
107. Macro Tag
Filtro Test
Función Operator
Global
108. Para generar Para modificar
contenido contenido
Macro
Filtro
Función
120. {% macro input(name, type) %}
...
{% endmacro %}
<div>{{ _self.input('edad') }}</div>
<input type="" name="edad" />
121. {% macro input(name, type) %}
...
{% endmacro %}
<div>{{ _self.input('edad', 'text') }}</div>
<input type="text" name="edad" />
122. {% macro input(name, type) %}
<input type="{{ type | default('text') }}"
name="{{ name }}" />
{% endmacro %}
126. {{"path( ) }} {% trans %}
{{ url( ) }}
caché las plantillas se
configurada cargan solas
127. app/cache/dev/twig
/* DesymfonyBundle:Default:index.html.twig */
class __TwigTemplate_8e822424720fee931876b7c05a9112b0 extends Twig_Template
{
protected $parent;
public function __construct(Twig_Environment $env)
{
parent::__construct($env);
$this!>blocks = array(
'title' => array($this, 'block_title'),
'pageid' => array($this, 'block_pageid'),
'contenido' => array($this, 'block_contenido'),
);