You could just name your components "home_sidebar", "contact_sidebar", "stuff_sidebar" ...
Then you can simply using if- or switch statement in your template to determine which page is actually loaded and then show corresponding component:
Or use a whitelist array of allowed pages:
Then you can simply using if- or switch statement in your template to determine which page is actually loaded and then show corresponding component:
PHP Code:
$slug = get_page_slug(false);
switch ($slug) {
case 'home':
get_component($slug.'_sidebar');
break;
case 'contact':
get_component($slug.'_sidebar');
break;
case 'stuff':
get_component($slug.'_sidebar');
break;
}
Or use a whitelist array of allowed pages:
PHP Code:
$slug = get_page_slug(false);
$whitelist = array(
'home',
'contact',
'stuff'
);
if(in_array($slug, $whitelist)) {
get_component($slug.'_sidebar');
}