Posts

Showing posts with the label twig

CodeIgniter: Add Session in Twig

To add the session variable on your twig template, you have to add the following line in your Twig library or controller. $this->_twig->addGlobal("session", $this->CI->session); Then on your twig template, you can print the session like this {{ session.userdata.username }} Since in CodeIgniter, the session stored by user is usually in the userdata array. Otherwise, you can just simply call the session variable and name {{ session.username }}

Install Anomareh PHP-Twig.tmbundle on Sublime Text 3

So this bundle for Sublime Text is made by Anomareh Basically, what it does is integrate Twig to the said IDE by providing syntax highlighting and auto-completion for Twig when using Sublime. So here's how to install the package. Download the package at https://github.com/Anomareh/PHP-Twig.tmbundle Unzip then copy all the files and folders In Sublime, click Browse Packages under the Preferences menu Create a directory named Twig on Packages folder Paste the files that you copied earlier into the Twig folder Restart Sublime Now, in your twig file, click on the bottom right of the sublime window (a drop up/down should appear) Select HTML (Twig) from the list of languages to enable the package. This should work on Sublime Text 2 as well.

Adding template engine Twig on CodeIgniter

Image
1. Download Twig vendor from http://twig.sensiolabs.org/ 2. Extract the files and copy the contents of the Twig-1.x.x\lib to /application/libraries/ Your library should have the Twig folder inside /libraries/Twig 3. Create a Twig.php inside the libraries folder then add the following code: class Twig { private $CI; private $_twig; private $_template_dir; private $_cache_dir; public function __construct($debug = false) { $this->CI =& get_instance(); self::requireTwigAutoloader(); Twig_Autoloader::register(); $this->CI->config->load('twig'); $this->_template_dir = $this->CI->config->item('template_dir'); $this->_cache_dir = $this->CI->config->item('cache_dir'); $loader = new Twig_Loader_Filesystem($this->_template_dir); $this->_twig = new Twig_Environment($loader, array( 'cache' => $this-...