Array in template for header menu
Permalink
Anyone willing to point me in the right direction on how to make any array that makes my header menu keeps the right colors?
What is have now is the following code:
So my menu items are related to a page Type.
But the client wants it to be related to a color sequence, let say (red, green, bleu, yellow, red, green, bleu, yellow, etc).
So that if they move the second menu item to the first position the new first menu item is red instead of green, all other menu-items move alone with it, based on the color sequence.
So I thought it would be best to make an array and past that to the <li>'s by a class, but I seem not to get it right.
Anyone have an idea?
Best,
Vincent
What is have now is the following code:
echo('<li id="' . str_replace('page_', '', $_c->ctHandle) . '"><a href="' . $pageLink . '" ' . $target . '>' . $ni->getName() . '</a>');
So my menu items are related to a page Type.
But the client wants it to be related to a color sequence, let say (red, green, bleu, yellow, red, green, bleu, yellow, etc).
So that if they move the second menu item to the first position the new first menu item is red instead of green, all other menu-items move alone with it, based on the color sequence.
So I thought it would be best to make an array and past that to the <li>'s by a class, but I seem not to get it right.
Anyone have an idea?
Best,
Vincent
What template are you using? The built-in Concrete5 one, or one of the custom ones from the forum or from my github page?
Hi Jordan,
For my leftsidebar I am using your github one, but for my headerNav I am using the built-in one from C5.5, please don't ask me way.
I have been thinking a bit further today and made a custom attribute with the four colors the site can handle, and placed it on the body tag, like:
class="<?=$c->getCollectionAttributeValue('pagina_kleur') ?>"
So now I can choose a color (pagina_kleur) for the page's, still have to figure out how to make the childpages inherent that color do, any idea?
I think that will do the sequence for the colors as well in de headerNav, but as a very novice in PHP I do not know how to loop through that in the 'echo <li' thing.
Hope that makes a bit of sence,...
For my leftsidebar I am using your github one, but for my headerNav I am using the built-in one from C5.5, please don't ask me way.
I have been thinking a bit further today and made a custom attribute with the four colors the site can handle, and placed it on the body tag, like:
class="<?=$c->getCollectionAttributeValue('pagina_kleur') ?>"
So now I can choose a color (pagina_kleur) for the page's, still have to figure out how to make the childpages inherent that color do, any idea?
I think that will do the sequence for the colors as well in de headerNav, but as a very novice in PHP I do not know how to loop through that in the 'echo <li' thing.
Hope that makes a bit of sence,...
Which menu do you want to do this color thing to? And is your header menu using the "header_menu" template or the default "view" template?
As for putting the same colors on the sub-menu items, I would use CSS for that -- so if the top-level item has a class, then in your stylesheet do something like:
As for putting the same colors on the sub-menu items, I would use CSS for that -- so if the top-level item has a class, then in your stylesheet do something like:
.pagina_kleur ul li { color: #xxxxxx; }
Sorry, I'm using the "header_menu.php" template, only changed the ul class. The color sequence has to work on the header menu only.
BTW: My CSS covers the side-menu correct if the body Tag is filled in correct, something like: <body class="green">. But therefor I have to fill in all custom attributes on childpage level. I was thinking the make it so that a child inherent his parent getCollectionAttributeValue('pagina_kleur'). But maybe I have to focus on the headerNav question first :)
Best,
Vincent
BTW: My CSS covers the side-menu correct if the body Tag is filled in correct, something like: <body class="green">. But therefor I have to fill in all custom attributes on childpage level. I was thinking the make it so that a child inherent his parent getCollectionAttributeValue('pagina_kleur'). But maybe I have to focus on the headerNav question first :)
Best,
Vincent
Okay, try this (in the header_menu.php template):
1) Add the following code ABOVE the "foreach($aBlocks as $ni)" line:
2) Add the following lines BELOW "else $isFirstClass = '';":
3) CHANGE the next line (echo '<li class="'.$navSelected.' '.$isFirstClass.'">';) to this:
-Jordan
1) Add the following code ABOVE the "foreach($aBlocks as $ni)" line:
$colorClasses = array('red', 'blue', 'orange', 'yellow'); //<--Set your color class names here $colorIndex = 0;
2) Add the following lines BELOW "else $isFirstClass = '';":
$colorClass = array_key_exists($colorIndex, $colorClasses) ? $colorClasses[$colorIndex] : ''; $colorIndex++;
3) CHANGE the next line (echo '<li class="'.$navSelected.' '.$isFirstClass.'">';) to this:
echo '<li class="'.$navSelected.' '.$isFirstClass.' '.$colorClass.'">';
-Jordan
Thanks a million Jordan!
Works like a charm.
I did not have a firstClass, I quess that referred to the home btn,
I must have taken that out somewhere alone the line, but it rocks like this, re-ordering the menu-items and still the same color sequence, I love it. Tears in my eyes.
best,
Vincent
Works like a charm.
I did not have a firstClass, I quess that referred to the home btn,
I must have taken that out somewhere alone the line, but it rocks like this, re-ordering the menu-items and still the same color sequence, I love it. Tears in my eyes.
best,
Vincent
Awesome! I'm so glad it worked.