fuel_nav: Appending Categories Not Working
I have been reading through old forum posts (
this and
this and
this) to figure out what I want to do. It's actually simple, I think, I just don't understand exactly how to do it.
On all pages made with the CMS, I have a sidebar menu for navigating each page's children. This sidebar menu is stored like this in /_variables/global.php:
$vars['sidemenu'] = fuel_nav(array('container_tag_id' => 'sidemenu', 'parent' =>uri_segment(1)));
I created a simple News module and I created a page (/news) with the CMS to output the data from the News module. The news page uses a special layout and also has its own _variables file.
I would like to create a special instance of the sidebar menu for use on the News page which links to Categories instead of the page's children. To do this, in /_variables/news.php I have put the following:
$all_cats = fuel_model('categories', array('select' => 'slug, name'));
foreach($all_cats as $ac){
$news_nav[$ac->name] = array('parent_id'=> 'news', 'location' => 'news/'.$ac->slug, 'label' => $ac->name);
}
$vars['sidemenu'] = fuel_nav(array('container_tag_id' => 'sidemenu', 'append' => $news_nav));
This, however, outputs empty. I have tried other things as well, like using the $nav or $append variables. It's more a matter of me not getting how to do it than anything. I did read about fuel_nav() here
http://docs.getfuelcms.com/helpers/fuel_helper#func_fuel_nav but that did not clarify for me.
Ultimately what I would want is for the news page to have each category listed in the sidebar menu, and then, after I solve that (simple) issue, on the category's page (news/category-slug), I would like a breadcrumb to trace back like Home > News > Category-Slug.
Any help is appreciated!
Comments
all_cats = fuel_model('categories', array('select' => 'slug, name')); foreach($all_cats as $ac){ $news_nav['news/'.$ac->slug] = array('parent_id'=> 'news', 'location' => 'news/'.$ac->slug, 'label' => $ac->name); } $vars['sidemenu'] = fuel_nav(array('container_tag_id' => 'sidemenu', 'append' => $news_nav));
The array key is the unique identifier that is used when doing the child/parent relationship.
$news_nav['news/'.$ac->slug] = array('parent_id'=> 'news'
to:
$news_nav['news/'.$ac->slug] = array('parent'=> 'news'
Now the side menu IS showing up including all of the pages made with the CMS and then, at the end, all of the categories. Any idea how to hide all things except the categories? I added 'root' => 'news' to $vars['sidemenu'] and it did hide all of the links I wanted to hide, but then it added a dead "News" link to the beginning of my side menu.
Any ideas?
$nav['news'] = array(.... 'active'=> ':children');
$nav['news'] = array('active' => ':children');
$vars['sidemenu'] = fuel_nav(array('container_tag_id' => 'sidemenu', 'append' => $news_nav, 'parent' => uri_segment(1)));
In /_variables/news.php I now have:
$all_cats = fuel_model('categories', array('select' => 'slug, name')); foreach($all_cats as $ac){ $news_nav['news/'.$ac->slug] = array('location' => 'news/'.$ac->slug, 'label' => $ac->name); } $vars['sidemenu'] = fuel_nav(array('container_tag_id' => 'sidemenu', 'append' => $news_nav, 'parent' => uri_segment(1)));
Thanks for your time helping me figure this out!
$all_cats = fuel_model('categories', array('select' => 'slug, name')); foreach($all_cats as $ac){ $nav['news/'.$ac->slug] = array('location' => 'news/'.$ac->slug, 'label' => $ac->name, 'parent_id' => 'news'); }
$all_cats = fuel_model('categories', array('select' => 'slug, name')); foreach($all_cats as $ac){ $append['news/'.$ac->slug] = array('location' => 'news/'.$ac->slug, 'label' => $ac->name, 'parent_id' => 16); } $vars['sidemenu'] = fuel_nav(array('container_tag_id' => 'sidemenu', 'parent' =>uri_segment(1), 'append' => $append));
For whatever reason, the parent_id would not work unless I used the numeric ID (which I found by going to /fuel/navigation and then editing the news item -- the ID showed up in the URL like this: /fuel/navigation/edit/16
Works just like I want!
Thanks admin for all of the time you offered helping with this!