-
Notifications
You must be signed in to change notification settings - Fork 14
/
README.txt
111 lines (70 loc) · 3.66 KB
/
README.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#The drupal 7 implementation of the Twig template language AKA TFD
##General information and installation
For more information about Twig, visit http://twig-project.org
To use this engine you will need to clone Twig from git (https://github.com/fabpot/Twig.git) into
your sites/all/libraries folder
#git clone https://github.com/fabpot/Twig.git ./sites/all/libraries/Twig
And this library also cloned into /sites/all/libraries in a folder called 'twig-for-drupal'
#git clone https://github.com/renebakx/twig-for-druapl.git ./sites/all/libraries/twig-for-drupal
Then move the twig.engine file to ./themes/engines/twig/ so that is on the same level as the phptemplate
engine drupal comes with.
To create a theme for twig, simply set engine = twig in your theme.info and start creating templates
Or you could simply use drush and the ready made installation profile from drupal.org at http://drupal.org/sandbox/ReneB/1528480
##More information and usage of Twig##
Please refer to the original project documentation found on http:/twig-project.org
##Drupal specific extensions
### Autorender
This version of the TWIG engine uses auto render to prevent themers get RSI from typing
{{node.field_somefield|render}} for every single field they want to render from the
render array (of doom) so the can safely type {{node.field_something}}
On rendering of the compiled template TFD check if the called variable is a string, callable or array.
If it's a string it simple does echo $string, if it's a callable it return a proper method() for it.
And if it's an array, it assumes it's a renderable array and maps it to the render($string); method of drupal.
This way the objects hidden with hide() are respected.
###Functions aka {% %} calls
**theme**, maps to the drupal theme() method
{% theme('node',vars.nodelist.node.1) %}
**render** and **hide** maps to the render() and hide() methods
{% hide(page.header) %}
**path_to_theme**, gives you the path the current theme, concat of base_path() + path_to_theme()
<img src="{%path_to_theme%}/assets/asset.jpg">
**with**, allows a scope-shift into a defined array.
{% with expr [as localName] [, expr2 [as localName2], [....]] {sandboxed|merged} %}
..Do Stuff..
{% endwith %}
For a more detailed example see /engines/twig/lib/TFD/TokenParser/With.php
**switch**, gives you a php like switch system
{% switch page.regions %}
{%case 'header %}
{% include 'header.tpl.html'}
{# no break needed, as this default #}
{%case 'content' fallthrough %}
{# do something and fall trough to next case #}
{% endswitch %}
###Filters (aka {{variable|filter}})
**dump**, if the devel module is activated, a dpr is issued. Or you can decide yourself by adding a parameter dump('dpm')
Parameters are : var_dump or v, print_r or p, dpr, dpm
**url** maps to the url() function
{{node.nid|url}}
**image_url** maps an image cache preset to a filename
{{node.fid|image_url('preset')}}
**t** maps to the t() method
{{'Download'|t}} or {{'Download'|t('nl')}}
**render** like the render function, but now as filter
{{page.footer|render}}
{{page.header.form.search|render}}
** hide, same the render function but then to hide();
### Expanding filters
You can expand twig with your own filters, by implementing hook_twig_filters(&$filters) in your own module
my_module_twig_filters(&$filters){
$filters['foo'] = new Twig_Filter_Function('my_module_twig_filter_foo');
}
function my_module_twig_filter_foo($var){
return $var .' with foo!';
}
Or just map it to an php function
my_module_twig_filters(&$filters){
$filters['rot13'] = new Twig_Filter_Function('str_rot13');
}
Jups.. it's that easy, so what are you waiting for.. get Twiggy with it :-)
\