Skip to content

Commit

Permalink
Create basic user guide for now. Need to add a page on filters.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathew Davies committed May 17, 2010
1 parent bdffe53 commit e1e98ac
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 0 deletions.
4 changes: 4 additions & 0 deletions guide/menu.twig.md
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)
23 changes: 23 additions & 0 deletions guide/twig.basic.md
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');
53 changes: 53 additions & 0 deletions guide/twig.config.md
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.
61 changes: 61 additions & 0 deletions guide/twig.custom.md
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>

0 comments on commit e1e98ac

Please sign in to comment.