Skip to content
This repository has been archived by the owner on Sep 17, 2019. It is now read-only.

geevcookie/CI-Twig-Parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

Plugin no longer supported. I suggest finding an alternative.

CI-Twig-Parser

Replace the default CodeIgniter parser with Twig.

Installation

  • Download Twig @ http://twig.sensiolabs.org/
  • Copy the Twig directory to application/third_party
  • Copy CI-Twig-Parser to the application folder.

And that should be it. :)

Usage

Because CI-Twig-Parser simply extends the default CI parser you can use it like you would the standard parser.

$this->parser->parse(<view>, <data>, <return>);

Where view is the view file you would like to parse, data is the data you would like to send through to the view and return is either true or false. If set to true the parser will return the result as a string. If set to false or omitted the parser will automatically append the result to the output.

Compatibility

CI-Twig-Parser is compatible with both the HMVC extension and Phil Sturgeon's epic Templating library. Links below:

Bonus

CI-Twig-Parser also makes CI functions available to you in the views.

By default all functions provided by libraries and helpers in the autoload.php config file are available. Change the register_autoload config item to FALSE to disable this.

If you have loaded more helpers or libraries in your controller simply run the below command to make the functions available to Twig.

$this->parser->checkFunctions();

This will check for all registered functions again and register them all as Twig functions.

If you would like to make a specific function available do this:

$this->load->helper('url');

$this->parser->addFunction('anchor');

In your view you can now use the anchor like this:

{{anchor('users/dashboard', 'Dashboard')}}

To make it even easier for designers you can also specify an alias for the function:

$this->load->helper('url');

$this->parser->addFunction('anchor', 'hyper');

The function can then be refered to by the alias like so:

{{hyper('users/dashboard', 'Dashboard')}}

Notes

This is my first library for CI so please be gentle. :) Also, let me know if you happen to run across any bugs or have any feature requests.

About

Replace the default CodeIgniter parser with Twig.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages