Changeset 956248
- Timestamp:
- 07/28/2014 09:30:51 PM (12 years ago)
- File:
-
- 1 edited
-
twig/trunk/readme.txt (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
twig/trunk/readme.txt
r956236 r956248 15 15 This WordPress plugin allows you to use the [Twig template engine](http://twig.sensiolabs.org) in your WordPress themes. It is really simple to use and even includes a template wrapper enabling you to use a master layout file to keep your themes D.R.Y. 16 16 17 = = Usage ==17 = Usage = 18 18 19 19 Let's start with the most simple use of this plugin to get you going: … … 24 24 Twig::View(); 25 25 ` 26 And that's it! The plugin will automatically know that you are in the index.php file, and try to find the template index.twigin any of the specified template folders.26 And that's it! The plugin will automatically know that you are in the **index.php** file, and try to find the template **index.twig** in any of the specified template folders. 27 27 We will later see how we can use this principle in a very creative manner. 28 28 … … 35 35 ]); 36 36 ` 37 The plugin will now look for the template post.twig.37 The plugin will now look for the template **post.twig**. 38 38 39 = = Template folder structure ==39 = Template folder structure = 40 40 You can offcourse keep all your templates organized into folders and render them like so: 41 41 … … 56 56 *If you find this an interesting aproach please read about template wrapping below.* 57 57 58 = = Passing variables to templates ==58 = Passing variables to templates = 59 59 To pass variables to our templates you pass the view function a context parameter. The context parameter is an array of variables of your choice: 60 60 … … 107 107 This clearly shows how we can use the WordPress template files (ex. **index.php**) to handle all our logic and let the [Twig template engine](http://twig.sensiolabs.org) do what it does best. 108 108 109 = = Remember Twig ==109 = Remember Twig = 110 110 111 111 Don't forget that you are using Twig. You can still use the awesome features of Twig such as: multiple inheritance, blocks, automatic output-escaping etc. 112 112 113 = = Template hierarchy ==113 = Template hierarchy = 114 114 115 115 This plugin utilizes WordPress template hierarchy in a very neat whay. Ex: … … 118 118 `page-about-me.twig -> page-about.twig -> page.twig`. Which will be very handy when we use master layout files. 119 119 120 = = Template wrapping ==120 = Template wrapping = 121 121 122 122 The plugin comes with a simple template wrapper. It allows you to specify a master layout file: **_layout.php** and exposes two new functions: … … 153 153 Because of the two new functions, if we have a file called **header-page.php** in our theme. It will be included when we visit a WordPress 'page'. 154 154 155 = = Template wrapper hierarchy ==155 = Template wrapper hierarchy = 156 156 157 157 The (second) best thing about the template wrapper is that it also follows the template hierarchy. Thus we can create the file: **_layout-page.php** and it will we used when visiting a WordPress 'page'. We can even create the file: **_layout-page-about.php** and it will be used on our about page.
Note: See TracChangeset
for help on using the changeset viewer.