-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create basic user guide for now. Need to add a page on filters.
- Loading branch information
Mathew Davies
committed
May 17, 2010
1 parent
bdffe53
commit e1e98ac
Showing
4 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
1. **Twig** | ||
- [Basic Usage](twig.basic) | ||
- [Configuration](twig.config) | ||
- [Custom Blocks](twig.custom) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
### Controller | ||
|
||
The twig module comes with a controller which you can easily extend. It's similar | ||
to how the current template controller works so you wont encounter too many issues | ||
switching over. | ||
|
||
[!!] Template names are generated automatically by default. The example below would | ||
look for welcome/index.html | ||
|
||
<?php defined('SYSPATH') or die('No direct script access.'); | ||
|
||
Class Controller_Welcome extends Controller_Template_Twig | ||
{ | ||
public function action_index() | ||
{ | ||
$this->template->variable = 'Hello World'; | ||
} | ||
} | ||
|
||
If you would prefer to load a custom template, then you can do so by assigning | ||
$this->template a Twig object. | ||
|
||
$this->template = Twig::factory('welcome'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Configuration | ||
|
||
#### Environment | ||
|
||
Name | Description | ||
--------------------|------------------------------------------ | ||
debug | Allow the use of the `{% debug %}` block | ||
trim_blocks | Will remove new lines after a block (mimic PHP behaviour) | ||
charset | Self explanatory | ||
base_template_class | Template name to use in the compiled classes | ||
cache | 1. **null** : Will create a directory under the system /tmp directory | ||
| 2. **false** : Turn off caching all-together | ||
| 3. **path** : Absolute path to cache directory | ||
auto_reload | Update the template when the source code changes | ||
|
||
|
||
#### Sandboxing | ||
|
||
Sandboxing can be enabled globally or can be used on a per include basis as follows: | ||
|
||
{% include "template.html" sandboxed %} | ||
|
||
For more information on sandboxing please check the | ||
[designer](http://www.twig-project.org/book/02-Twig-for-Template-Designers) | ||
and [developer](http://www.twig-project.org/book/03-Twig-for-Developers) docs. | ||
|
||
[!!] The methods and properties array takes a class name as the key and an array | ||
of values. | ||
|
||
Name | Description | ||
-----------|------------------------------------------ | ||
global | Should sandboxing be enabled globally? | ||
filters | White-listed filters | ||
tags | 〃 tags | ||
methods | 〃 methods | ||
properties | 〃 properties | ||
|
||
|
||
#### Loader | ||
|
||
The options here should not need to be changed and are only really for advanced | ||
usage. | ||
|
||
Name | Description | ||
----------|------------------------------------------ | ||
class | Used to load the template files. Should implement the `Twig_LoaderInterface` interface | ||
extension | Template extension, default is html | ||
options | Array of options passed the loader `__construct` | ||
|
||
|
||
#### Extensions | ||
|
||
The extensions item is just an array of extension class names. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# Custom Blocks | ||
|
||
The modules comes with a few pre-made blocks. | ||
|
||
|
||
### html | ||
|
||
Allows you to use the html helper in the following format | ||
|
||
{% html.anchor "http://google.com", "Google" %} | ||
|
||
All html helper functions are available and take arguments as you would expect. | ||
|
||
### form | ||
|
||
The same as the html helper, just replace `html` with `form` and `anchor` with a form | ||
function | ||
|
||
### cache | ||
|
||
This makes use of the Kohana fragment cache and provides a simplified interface | ||
for creating cachable blocks of content. | ||
|
||
{% cache "key" %} | ||
This will be cached. | ||
{% endcache %} | ||
|
||
You can also pass a lifetime value in seconds as the second argument. | ||
|
||
{% cache "key", 3600 %} | ||
This will be cached. | ||
{% endcache %} | ||
|
||
Will be cached for one hour. | ||
|
||
### url | ||
|
||
Use reverse routing in your templates. | ||
|
||
{% url "default", ["action":"register"] %} | ||
|
||
The first argument is the route name and the second is a key:value array. So the above | ||
would produce: | ||
|
||
http://example.com/welcome/register | ||
|
||
You can set certain keys to `null` so the route will use the default segment in | ||
the bootstrap.php or init.php files. If we wanted to remove `welcome` for example: | ||
|
||
{% url "default", ["controller":null,"action":"register"] %} | ||
|
||
would produce: | ||
|
||
http://example.com/register | ||
|
||
#### Generating links | ||
|
||
Unfortunately you can't mix the url block with the html block and so if you need | ||
to use reverse routing you'll need to construct the html anchors manually like so: | ||
|
||
<a href="{% url "default", ["action":"register"] %}">Register</a> |