Autonav classes

Permalink 1 user found helpful
Hello. Im designing a menu and i need to "catch" the classes for my "li"s in the autonav so i can style each one individually. Is this possible through the autonav?

Example.

i want

home - to be the color green
contact - to be the color blue
blog - to be the color yellow
etc.

is this possible?

 
mesuva replied on at Permalink Best Answer Reply
mesuva
It's very possible and not too hard to achieve, but you'll need to create a block template override to be able to customise the output of the autonav block.

You would take a copy of /concrete/blocks/autonav/view.php and place it in
/blocks/autonav/ (which you'll need to create)

Then you can edit this view.php file to include extra classes. There are probably a few ways to do this, but I would create a page attribute that you can add to a page, that gets pulled in as an extra class. I won't post the code for this yet, but I'm happy to do this if you're not sure how to achieve this.
berteldk replied on at Permalink Reply
Ok i have copied the autonav folder and pasted it in the blocks folder - inside the view.php i will need som help with edit if you have the time.



im guessing i need to alter something between here?

$thisLevel = $ni->getLevel();
         if ($thisLevel > $lastLevel) {
            echo("<ul>");
         } else if ($thisLevel < $lastLevel) {
            for ($j = $thisLevel; $j < $lastLevel; $j++) {
               if ($lastLevel - $j > 1) {
                  echo("</li></ul>");
               } else {
                  echo("</li></ul></li>");
               }
            }
         } else if ($i > 0) {
            echo("</li>");
         }
mesuva replied on at Permalink Reply
mesuva
Here's an edited view.php from the autonav block (concrete5.5.1):

All you would need to do is create a new page attribute with the handle 'nav_class'. Then for each page, add the attribute and set it to something you like.

<?php 
   defined('C5_EXECUTE') or die("Access Denied.");
   $aBlocks = $controller->generateNav();
   $c = Page::getCurrentPage();
   $containsPages = false;
   $nh = Loader::helper('navigation');
   //this will create an array of parent cIDs 
   $inspectC=$c;
   $selectedPathCIDs=array( $inspectC->getCollectionID() );
   $parentCIDnotZero=true;   
   while($parentCIDnotZero){
      $cParentID=$inspectC->cParentID;
      if(!intval($cParentID)){
         $parentCIDnotZero=false;
      }else{
berteldk replied on at Permalink Reply
Umphf... Im not so advanced, i dont understand it to be honest... Is there any way you can explain it more cleary? Not that you probabely arent clear, im just not so good yet :/

Page attribute??
mesuva replied on at Permalink Reply
mesuva
No probs.

Replace the code in your overriding view.php with what I've pasted in.

Then go to the dashboard and find Page Attributes (under Pages and Themes). You'll need to create a new attribute of type 'text', with the handle 'nav_class', and a name like 'Navigation Class'.

Once you've done that, you can go edit a page and edit it's properties. Under the custom attributes tab in the properties, add this new attribute and type in what you want the class to be for its menu item in the list.

For example, you would go to your contact page, add this attribute and type in 'contact'. This word will appear as a class in the autonav output for this page.
mesuva replied on at Permalink Reply
mesuva
I should say - page attributes are little pieces of information you can give to individual pages. It could be a checkbox, or a piece of text, a date or even a file.

You can create your own attributes and do all sorts of useful things with them. One of my favourite things about concrete5.
berteldk replied on at Permalink Reply
Awesome... i will test this as soon as i get home! I get back to you later if im running into more troubles. Thank you for taking your time to help me out.
berteldk replied on at Permalink Reply
Ok so i have created a attribute under:

Pages & Themes -> Attributes -> Text GO -> handle:nav_class -> Name: Navigation Class -> Add Attribute

Then i go to Pages & Themes -> Page Types -> (and i have 3 choices: default / settings / composer) I chose settings for the pagetype i want to change?? and mark the attribute (the one i created) in the bottom? -> Update Page Type

Then what? sorry if im a bit slow....

EDIT: I found out i need to go to the sitemap -> (chose site) -> properties -> custom attributes and then i see the name of the handle i made (Navigation Class) in the buttom. I then try to fill in a name here, in my case i used testing - but i cant seem to find that tag with firebug anywere in my autonav ?

Edit: I got it now... Had forgot to uninstall old autonav and install the new autonav :-)) Now it works and it gives the class to the menu. Thank you for your help.
berteldk replied on at Permalink Reply
However i cant seem to rename the autonav in the block folder? Its not possible to call it something else so you can see which is which? like autonav_custom etc.?
mesuva replied on at Permalink Reply
mesuva
Yes, if you create a folder /blocks/autonav/templates (you might already have this)
you can put in view files in there, but call them different things, e.g.
/blocks/autonav/templates/custom_classes.php (where custom_classes.php used to be your view.php file).

Then when you are editing a page with an autonav on it, you can left click on it and pick 'Custom Template'. In there, you can select which template override you want to use.

You don't actually need to copy over the whole block, you only need put into the top level blocks folder the files that you want to override.
berteldk replied on at Permalink Reply
Ahh this was great! Thank you man. I have another question for you, i have sent you a PM - but only take the time to answer if you got the time - if not its totally ok, you just seems like a guy who knows what your doing.

thx for all the help.