- CodeIgniter 2
- CodeIgniter Sparks
- Install Sparks if you haven't done so already.
- Install the Y'ALL spark (see here if you don't know how).
- Optional: Set your default layout in
config/yall.php.
- Default is
layouts/default. - Depending on what you set, make sure that the files actually exist in your
application/views/directory. For example,layouts/defaultmaps toapplication/views/layouts/default.php.
Set a variable to be used in the layout. Setting $encode = TRUE will pass the value through htmlentities().
Example: $this->yall->set('title', 'My Page Title');
Set a variable to be used in the layout and partials (although you must call this before setting your partials). Setting $encode = TRUE will pass the value through htmlentities().
Example: $this->yall->set_global('username', 'admin');
Set a list or array of variables to be used in the layout. Setting $encode = TRUE will pass the value through htmlentities().
Example:
$this->yall->->set_global([
// [{name}, {value}, {encode}]
['some_page_title', 'Hello World', false],
['another_page_title', 'Yall package']
]);Set a view to be used in the layout as a partial. $data is an array of variables to be sent to the view being called.
Example: $this->yall->partial('main_content', 'users/login');
Renders and outputs the layout. You can override the default layout by setting the $layout parameter. If you want to return the rendered view, set $return = TRUE.
Example: $this->yall->render();
Be one of the cool kids and use method chaining:
$this->yall->set('title', 'My Title')
->set('meta_description', 'Yay for SEO!', TRUE)
->set_global('my_var', 'I will be available in partials, too!')
->partial('main_content', 'pages/about', array('foo' => 'bar'))
->render();