Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
How to create a Theme using a Template engine like smarty
  • I am trying to create a new theme using the depot project. How to I modify this controller so that it 
    1. calls the Parser class and the View_Smarty class for the smarty template engine
    2. uses the smarty templates in the themes folder

    class Controller_Homepage extends Controller_Base_Public
    {
    /**
    * The application homepage
    *
    * @access  public
    * @return  Response
    */
    public function before()
    {
    // call the parent to run the setup
    parent::before();

    // if this is a request for the index action, switch to the homepage layout template
    \Request::active()->action == 'index' and \Theme::instance()->set_template('default');
    }


    /**
    * The application homepage
    *
    * @access  public
    * @return  Response
    */
    public function action_index()
    {
    // no code, the homepage is static atm
    }

  • HarroHarro
    Accepted Answer
    You don't need to call the Parser class. If you load the package it works automatically.

    The theme class works with Views, if you want to call a template engine with the parser class you'll have to tell the parser which engine to use. You do that using the extension, which in case of Smarty is ".smarty" (because ".tpl" was already used. If you want to use that, copy the parser config to app/config, and modify it). By default it uses ".php", using "default" is the same as using "default.php".

    So it will become \Theme::instance()->set_template('default.smarty'); The same for all partials.

  • Thanks. I now understand how the themes and template engines work!

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion