Skip to content

Instantly share code, notes, and snippets.

@Vheissu
Created September 25, 2012 22:23
Show Gist options
  • Save Vheissu/3784826 to your computer and use it in GitHub Desktop.
Save Vheissu/3784826 to your computer and use it in GitHub Desktop.
Dynamic Sidebar Functionality
// This version does a simple file include
// Like you would in your template view file
// Using the standard CI Views functionality
function get_sidebar($slug = '')
{
// No slug? Just get sidebar.php then
if ($slug == '')
{
include_once APPPATH.'views/sidebar.php';
}
else
{
include_once APPPATH.'views/sidebar-'.$slug.'.php';
}
}
// This function will include the sidebar file silently
// Then store the returned data into a variable
// And then echo it's contents
function get_sidebar($slug = '')
{
// No slug? Just get sidebar.php then
if ($slug == '')
{
ob_start();
include_once APPPATH.'views/sidebar.php';
$sidebar = ob_get_clean();
}
else
{
ob_start();
include_once APPPATH.'views/sidebar-'.$slug.'.php';
$sidebar = ob_get_clean();
}
echo $sidebar;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment