Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Kohana module to support clean integration of Smarty template engine with Kohana views
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
smarty
LICENSE.md
README.md

README.md

Kohere

Kohere is a module for the Kohana PHP framework to support clean integration of the Smarty template engine with Kohana views.

Documentation

Setup instructions

  1. Install Kohana (3.2+)
  2. Activate module in your Kohana bootsrap.php:
    'smarty'     => MODPATH.'smarty',
    
  3. Extend your controller class (Controller_MYNAME) from Controller_Smarty
  4. Organize template directories as you want within application/views/. You then can optionally set the path to the template directory that you want to invoke templates from. Examples:
        $this->view->render('FOLDER_NAME/TEMPLATE_NAME'); // under /application/views/
        $this->view->render('TEMPLATE_NAME'); // will render template under current controller folder
        $this->view->render('/TEMPLATE_NAME'); // will render template under views/ directory
    
    By default, the module looks for templates in the following structure
    /views
          /controller        // controller name here
                /name1.tpl   // controller action name here
                /name2.tpl   // second controller action
    
    so if you have such template structure you can use:
    class Controller_Dashboard extends Controller_Smarty {
    
        public function action_name1()
        {   
             // if value 'auto_render_template'  == true will render name1.tpl template automatically
        }
    
        public function action_name2()
        {   
             // render name2.tpl
            $this->view->render('name2');    
        }
    }
    
  5. Assign variable values for use in templates by either:
    1. Using native Smarty function:
      public function action_name1()
      {    
            $this->view->assign('test', $value);
      }   
      
    2. Or use the Kohana render() method and pass data to the view:
      public function action_name1()
      {    
           $array_of_variables = array
           (
                 'test1' => $test1,
                 'test2' => $test2,
             )
      
            $this->view->render('name1', $array_of_variables);
      }
      

Using with other Kohana modules

  • The module does not support Kohana's cascading file system. To use this module with views in other modules, you must change the templates directory from 'APPPATH/views' to 'MODPATH/modules/mymodule/views/':
    1. in 'MODPATH/modules/mymodule/views/' create template accordingly to above instructions
    2. create 'MODPATH/modules/mymodule/classes/controllers/mycontroller.php
    3. extend controller class from Controller_Smarty
    4. in the 'mymodule' controller add Controller_Smarty and add these lines to before method:
      class Controller_Mycontroller extends Controller_Smarty {
             public function before()
             {    
                  parent::before();
                  $this->view->set_template_dir(MODPATH.'/modules/mymodule/views/');
             }
             
             public function action_name1()
             {    
                    $this->view->assign('test', $value); // will render MODPATH/modules/mymodule/views/name1.tpl 
             }  
      }
      

Reporting bugs

If you've stumbled across a bug, please help us out by reporting the bug you have found. Simply log in or register and submit a new issue, leaving as much information about the bug as possible, e.g.

  • Steps to reproduce
  • Expected result
  • Actual result

This will help us to fix the bug as quickly as possible. Or, even better, if you'd like to fix it yourself feel free to fork us on GitHub and submit a pull request!

LICENSE

This software is released under the Apache 2.0 open source license.

Something went wrong with that request. Please try again.