Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Rendering partials in a controller template
  • Hello, I'm using controller templates and in the template view aiming to do little more than call other partials to handle some commonly used chunks (head, header, footer). I figured I'd be able to pass in things like the title to the head partial from the template view:
    <?php $data = array($title); ?>
    <?php echo View::forge('_head', $data); ?>
    

    It seems that when I try to do this though, the page renders the partial well enough, but there's an error where the title is echo'd:
    <div>
     <p>strong>Notice!</strong></p>
     <p>ErrorException [ Notice ]: Undefined variable: title</p>
     <p>strong>APPPATH/views/_head.php @ line 4:...</strong></p>
    

    If I echo the $title var in controller template view it renders the value properly, so its only being lost in the process of rendering the partial. What's happening?
  • You have to set your $data as global, so that your partial gets its value : In your controller :
    // assign global variables so all views have access to them
    $view->set_global('data', $data);
    
    Check the docs here : http://docs.fuelphp.com/general/views.html - part 'Method 1 (using example views above and lazy rendering)' Let me know if it works, and anyone correct me if I'm wrong

Howdy, Stranger!

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

In this Discussion