Skip to content

Instantly share code, notes, and snippets.

@xavierbriand
Created January 4, 2012 23:10
Show Gist options
  • Save xavierbriand/1562741 to your computer and use it in GitHub Desktop.
Save xavierbriand/1562741 to your computer and use it in GitHub Desktop.
Twig training 2
<html>
<head>
{% block head %}
<link rel="stylesheet" href="style.css" />
<title>{% block title %}{% endblock %} Sensio</title>
{% endblock %}
</head>
<body>
<div>{% block content %}{% endblock %}</div>
<div>
{% block footer %}&copy; sensio{% endblock %}
</div>
</body>
</html>
{% extends "base.html" %}
{% block title %}Index{% endblock %}
{% block head %}
{{ parent() }}
<link rel="stylesheet" href="grid.css" />
{% endblock %}
{% block content %}
<h1>Index</h1>
...
{% endblock %}
{# block #}
{% block title 'mon titre'|title %}
{{ block('title') }}
{% block sidebar %}
{% block inner_sidebar %}
...
{% endblock inner_sidebar %}
{% endblock sidebar %}
{# extends #}
{% extends ajax_actif ? 'ajax.html.twig' : 'ss_ajax.html.twig' %}
{% extends 'layout_'~locale~'.html.twig' %}
{% extends ['layout_'~locale~'.html.twig', 'layout.html.twig'] %}
{# forms.html #}
{% macro txtarea(name, value, cols) %}
<textarea cols="{{ cols|default(5) }}" name="{{ name }}">
{{ value|e }}
</textarea>
{% endmacro %}
...
{# shortcuts.html #}
{% macro wrapped_txtarea(name, value, cols) %}
{% import "forms.html" as forms %}
<div class="field">
{{ forms.txtarea(name, value, cols) }}
</div>
{% endmacro %}
{# template.html #}
{% from 'forms.html' import txtarea as input_long_text %}
{{ input_long_text('name', article.body, null) }}
{# blocks.html.twig #}
{% block sidebar %}<ul>...{% endblock %}
{# content.html.twig #}
{% extends "layout.html.twig" %}
{% use 'block.html.twig' %}
{% block title %}{% endblock %}
{% block content %}{% endblock %}
{# content.html.twig #}
{% extends "layout.html.twig" %}
{% use 'block.html.twig' with sidebar as my_sidebar %}
{% block sidebar %}
{{ block('my_sidebar') }}
{% endblock %}
{% block title %}{% endblock %}
{% block content %}{% endblock %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment