Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Question about theme override
  • Hi,

    In first, my theme.php config file contains :

    'active' => 'default',
    'paths' => array(APPPATH.'themes'),
    'use_modules' => true,


    I'll try to explain my problem : 

    - I have a module "backend" which contains a theme, and base controller "\Backend\Controller_Index"
    - I have a module "menu" which contains an administration section ( \Menu\Controller_Backend )
    - The "\Menu\Controller_Backend" extends "\Backend\Controller_Index", and i want to use the theme which is placed in the module "backend"


    1. In \Backend\Controller_Index, if i do in before method : $this->theme->set_template("template.php")
    - When i'm in "/backend/index" it's work
    - When i'm in "/menu/backend" It's don't found template.php (it's logic, i'm in menu module)

    2. In \Backend\Controller_Index, if i do in before method : $this->theme->set_template("backend::template.php")
    - It's work in all case, yes. But problem : Now i can't override my template in my theme folder ( /app/themes/default/backend/template.php )



    My question is how i can use a theme which is in a other module, and have possibility to override it in the app without needing to modify the module ?
  • I've found a solution, but i don't know if it's a good way, or if better methods exist : 


    In \Backend\Controller_Index, i created an action that instantiate a Theme class, i set_template, and i return it :

        public function action_theme()
        {
            // Set template 
            $this->theme = \Theme::instance();
            $this->theme->set_template('template.php');

            return $this->theme;
        }

    And in the before method in \Backend\Controller_Index i do it :

            if (\Request::is_hmvc())
            {
                $this->theme = $this->action_theme();
            }
            else
            {
                $this->theme = \Request::forge('backend/index/theme')->execute()->response()->body();
            } 


    It's work fine, if i'm in menu module, the function use HMVC request for get the theme object, otherwise i get the theme object normally
  • HarroHarro
    Accepted Answer
    I assume you want a uniform look and feel for your application. In which case page templates are always global, not linked to a module or a controller in a module, but defined at the theme level.

    Like you would have with CMS applications, you have different templates (2 columns, 3 columns, with- and without footer section, etc). The sections of the template are filled with partials. Some will be assigned central as well (for example in your base controller's before), like a header, footer, menu, etc. some will be assigned by controller method (either directly called or by HMVC).

    In this system the controller never has to worry about templates or layouts, a controller method sets a theme partial (in case of a directly called controller) or returns a view (in case of an HMVC call). It is not aware of it's surroundings.

Howdy, Stranger!

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

In this Discussion