Welcome Guest, Not a member yet? Register   Sign In
Hard Searching a easy use of Twig in CI
#2

[eluser]wiredesignz[/eluser]
This was a plugin I have used with CI and Twig.

Installed as plugins/twig_pi.php however with CI 2.0 you may need to load it as a package from the third_party directory or even modify it to become a helper. It is not designed to be instantiated as a CI library.

Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

include_once 'Twig/Autoloader.php';
Twig_Autoloader::register();

class mxView
{
    private $config, $twig;
    
    function __construct()
    {
        $this->config =& get_instance()->config;
        
        $reload = TRUE;
        $cache = $this->config->item('cache_path');
        $templates = FCPATH.$this->config->item('theme','settings').'views/';        
        
        $environment = array(
            'debug'               => FALSE,
            'trim_blocks'         => FALSE,
            'charset'             => $this->config->item('charset'),
            'base_template_class' => 'Twig_Template',
        );    
        
        $loader = new Twig_Loader_Filesystem($templates, $cache, $reload);
        $this->twig = new Twig_Environment($loader, $environment);    
    }
    
    function load($template, $data = array(), $return = FALSE)
    {        
        $view = $this->twig->loadTemplate($template);
        $data = array_merge($this->config->item('settings'), $data);
        return ($return) ? $view->render($data) : $view->display($data);        
    }
}

Usage:
Code:
$view = new mxView();
$data['widget'] = new mxWidget();
$this->output->final_output = $view->load('layout.tpl', $data, TRUE);


Messages In This Thread
Hard Searching a easy use of Twig in CI - by El Forum - 10-19-2010, 12:58 PM
Hard Searching a easy use of Twig in CI - by El Forum - 10-19-2010, 09:35 PM
Hard Searching a easy use of Twig in CI - by El Forum - 10-20-2010, 02:39 PM
Hard Searching a easy use of Twig in CI - by El Forum - 10-20-2010, 03:16 PM
Hard Searching a easy use of Twig in CI - by El Forum - 10-22-2010, 11:12 AM
Hard Searching a easy use of Twig in CI - by El Forum - 10-22-2010, 05:48 PM
Hard Searching a easy use of Twig in CI - by El Forum - 10-22-2010, 06:15 PM
Hard Searching a easy use of Twig in CI - by El Forum - 10-22-2010, 07:34 PM
Hard Searching a easy use of Twig in CI - by El Forum - 10-23-2010, 08:28 AM



Theme © iAndrew 2016 - Forum software by © MyBB