More Related Content Similar to Twig Templating Similar to Twig Templating (20) Twig Templating7. Twig
- Provides Pattern Consistency
- Solves Complex Control Flow
- Template Inheritance & Macros
- Fully Extendable
13. VIA TARBALL OR ZIP
https://github.com/fabpot/Twig/tags
- Unpack
- Move files to your project folder
16. Delimiters
{{ ... }}
- displays something
{% ... %}
- evaluates an expression (loops, tags, cond.)
{# ... #}
- comments code blocks
24. LITERALS
String = “Manong Johny”
Integer = 100000000
Float = 100000000.00
Array = [“pdaf”, “dap”]
Hash = {“key” : “value”}
Boolean = true/false
Null = null
25. SETTING VARIABLES
{% set str = 'value' %}
{% set arr = [1, 2, 3] %}
{% set hash = {'a' : 1, 'b': 2 } %}
{% set combine = ['a' : { 'b': 2 }] %}
29. MACROS
- acts like functions in regular
programming language
- default argument values are defined
by using the default() filter
- arguments are always optional
31. ESCAPING
- escapes a string for safe insertion
into the final output
{{ var|escape }}
{{ var|e }}
{% autoescape %}
….
{% endautoescape %}
32. ESCAPING
Default Escape : {{ str|escape }}
<p>Hello World!</p>
JS Escape : {{ str|escape('js ') }}
x3Cpx3EHellox20Worldx21x3Cx2Fpx3E
CSS Escape : {{ str|escape('css ') }}
3C p3E Hello20 World21 3C 2F p3E
URL Escape: {{ str|escape('url') }}
%3Cp%3EHello%20World%21%3C%2Fp%3E
39. BLOCK
- are used for inheritance and act
as placeholders and replacements.
{% block content %}
…..
{% endblock %}
41. EXTENDS
- can be used to extend a template
from another one.
{% extends “layout.twig” %}
45. INCLUDE
- includes a template and return
the rendered content of that file
into the current namespace.