Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Partial undefined in the template
  • Hi

    I (usually) use partials without problem, but i started a new project, quitely install the fuel project, and made a public controller extended from Controller_Hybrid, and set a partial. And the partial is undefined in th template.

    Controller code (before function) 

            $tpl = Config::get('theme_to_use') or 'default';
            
            $this->theme = 'public'.DS.$tpl;
            
            $this->template = $this->theme.DS.'templates'.DS.'home.twig';
            
            parent::before();
            
            $this->ti = \Theme::instance();
            
            $this->ti->set_template($this->template);
            
            $this->ti->get_template()->set('title', Config::get('title'));
            
            $this->ti->set_partial('header', $this->theme.DS.'views'.DS.'global'.DS.'header.twig')
                    ->set('title_header', Config::get('site_name'));

    What am I doing wrong ? In the template, (I use twig), the partial var is undefined. But when i debug all defined vars, i got my partial as a child of the object(Fuel\Core\Theme)#21. So it work more or less, just the partial var not initialised. I have to tell i'm a little tired and i don't see where the error come from.

    Thanks 
  • Partials are in $partials, so you need $partials['var'] and not $var (never used twig, so I don't know it's correct notation).

    p.s. this is better and a bit quicker:

    $tpl = Config::get('theme_to_use', 'default');


  • Thanks, i forgot this trick. 

    For partial, you wrote $partials with a S at the end, the doc say $partial without S. Anyway, i try the two, $partial and $partials are null.

    Edit : for twig, $partial['var'] become {{ partial.var }}, but it's irrelevant anyway.

    Edit: Solved. The parent::before was guilty. The parent before() create a template object from the template string given. Obviously, the Theme instance get_template method need a string. It works with a template object, but the partials aren't rendering. Thanks you though, Harro. 

Howdy, Stranger!

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

In this Discussion