Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Set and get variables using theme templates
  • Hi there, 

    Maybe a stupid question but how do i set and get variables (in my partials) using themes? 

    For example i set

    $this->theme->get_template()->set('title', 'My Title');
    $this->theme->set_partial('header', '_partials/header');

    How can i get the $title var inside the header partial? At the moment fuel returns 

    Undefined variable: title

    ..when i call for $title in my header partial.


  • HarroHarro
    Accepted Answer
    There are no stupid questions, just stupid answers. ;-)

    The View object has a get() method too, so you can do
    $title = $this->theme->get_template()->get('title', 'not-set');
    This does mean you need to have access to $this->theme in the partial though. It would be more logical to set the title on the header partial though, if that is where you need it.
  • Well i need the current page title that is set in the action_index. But i dont know how to get the variable inside the header partial. Is there a way to pass the variable to the header partial from an action?
  • Same way as with the template:

    $this->theme->get_partial('header')->set('title', 'My title');

  • Hah, ok this is stupid. I know,. I stumbled on it on the docs now. Thanks anyway. 

    I've found your post (here). It is a very useful post to lay out a good base foundation. 
    I had trouble figuring out how to structure everything using themes.

    Thanks

Howdy, Stranger!

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

In this Discussion