Welcome Guest, Not a member yet? Register   Sign In
phptal & ci integration
#11

[eluser]MaD HamsteR[/eluser]
[updated] 24.11.11

Hi there.

I wrote a little wrapper to help you integrate and use this magnificent tempalte engine with CI.

Instructions

1. Download PHPTAL
2. Extract it to /system/application/libraries/phptal/ folder
3. Create file tal.php in /system/application/libraries/ folder
4. Put this code inside tal.php file

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

//Path to PHPTAL library, i used 1.2.0
include 'phptal/PHPTAL.php';


/**
* Wrapper for PHPTAL tempalte engine
*/

class Tal extends PHPTAL{


    function __construct()
    {

        //Call PHPTAL constructor (because we can)

        parent::__construct();


        /**
        * Use CI config to set encoding, templates and compiled templates path
        */

        $CI = &get;_instance(); //BUGGGGGG!!!! CI FORUM BUG, REMOVE the ; SYNTAX ERROR!


        /**
        * You can change paths if you need to
        */

        $cache_path = $CI->config->item('cache_path');

        if(empty($cache_path))
        {
            $cache_path = APPPATH.'cache/';
        }


        $this->setEncoding($CI->config->item('charset'));
        $this->setTemplateRepository(APPPATH.'views/');
        $this->setPhpCodeDestination($cache_path);


    }


    /**
    * @param string  (template name or path)
    * @param boolean (set TRUE to return page content)
    * @result mixed (depends on second parameter)
    *
    * This method returns or echoes parsed tempalte content
    */

    function display($tpl, $return=false)
    {

        $this->setTemplate($tpl);

        if($return){

            return $this->execute();

        }

        $this->echoExecute();

    }



}


?>

5. Set autoload "tal" library in autoload config file, or preload it manually in your script

Thats it.

Use like:

Code:
//Some controller

    function index()
    {


        $this->tal->title = 'Just another blog...';

        $this->tal->display('index.html');


    }


Messages In This Thread
phptal & ci integration - by El Forum - 10-16-2007, 11:06 AM
phptal & ci integration - by El Forum - 10-16-2007, 11:46 AM
phptal & ci integration - by El Forum - 10-16-2007, 11:54 AM
phptal & ci integration - by El Forum - 10-16-2007, 05:43 PM
phptal & ci integration - by El Forum - 11-10-2007, 01:35 PM
phptal & ci integration - by El Forum - 11-10-2007, 02:35 PM
phptal & ci integration - by El Forum - 11-10-2007, 02:57 PM
phptal & ci integration - by El Forum - 11-10-2007, 04:40 PM
phptal & ci integration - by El Forum - 11-11-2007, 02:07 AM
phptal & ci integration - by El Forum - 08-29-2008, 06:31 AM
phptal & ci integration - by El Forum - 08-21-2009, 07:27 AM
phptal & ci integration - by El Forum - 09-04-2009, 05:32 PM
phptal & ci integration - by El Forum - 06-07-2010, 04:19 AM



Theme © iAndrew 2016 - Forum software by © MyBB