Okay here's a question for everyone...probably a simple answer, but my knowledge of internal Joomla! code isn't strong enough to know it.

I'm working on a site with a custom template. The site nav has hundreds of links, but all of them cascade from 4 top-level parents. Each of the top level parents uses it's own "colour theme" (blue, red, yellow, green).

What I need to do is style the links used with each top-level section to match that menu's colour theme.

So, if I'm on a page that is the parent OR any sub-level ItemID of that parent, any links on the page should display red.

The problem I have is determining what TOP LEVEL ITEMID is currently being used. Without adding CSS to each and every ItemID in each section (which would be unwieldy to say the least), I don't know how to achieve this.

So, does anyone know how I can return the value of the top-level ItemID regardless of the current ItemID?

Thanks in advance :)

Dan

Views: 57

Replies to This Discussion

The only way I see is to cascade from the top level's class. This shouldn't be bad bc you can't have too many top level items right?
So if the top level's class is .item25
then
.item25 a {
color:red;
}
would turn all links under that item red.

I feel like I misunderstood your question somewhere though, so apologies if I did :)
Hey Kyle, thanks for the reply.

I'll try to elaborate - basically it's any links within the content body I need to style up, and the issue is that these links fall outside of the menu CSS cascade. So, I could style the child links within the menu using this method, but nothing outside of the menu.

I currently echo the ItemID into the main wrapper for the template:

id="wrapper" class="id $item_id; ? >"

...but what I want ideally is something like:

id="wrapper" class="id $top_level_parent_item_id; ? >"

Make sense?

(sorry had to strip some tags but you get the idea)
Hi Dan
Thanks for your message. May I point out though that our mission here is more a professional development one. If you have code level how-to Qs, please instead use the forum.joomla.org. Thanks
Dex
Hi Dex,

Not sure I understand the problem. This is a professional development question. I'm a professional, working on a development, and I have a question.

With all due respect to the Joomla.org forums, I wouldn't hold out much hope getting a useful reply I'm sorry to say. At least here, posted in the Template Developers section, I can target fellow template developers who may notice something that I am missing.

I'm not just out for some free support here...whether I get an answer or not, I'll still implement something that works, I was just interested to see how others would tackle the problem.

If we can't discuss things like this in a template developers group forum, then what can we discuss?
Well, since you clearly seek to grow stronger on your Joomla! framework knowledge, I wont tell you outright how to do it.
But point you in the right direction :)
Noticed how mod_breadcrumbs always seems to know your menu hierarchy? ;)

@Dex if you don't know the answer to a question being asked, don't tell them the seeker to go someplace or indirect insults. The mission for this site is to be a: "Developers and Site Builders Network". Sending someone to forum.joomla.org accomplish this goal, how?
If DanL were asking how to add a stylesheet to the header, or needed help installing k2, I would agree with you. But what's he's asking about is on a more advanced level, that only a couple of the devs I know of actually know how to do.
Because of that many people, not just DanL would benefit from him figuring it out :)
I think it's a good question, it's not something I know and was hoping to learn, too.

Let's go easy on @dex as she's trying to help set boundaries. We don't want to duplicate the forum functionality - it's a worthwhile question to raise, once in awhile. It's not like these lines are clear, at least not to me.
Thanks for your replies folks.

@Dex, I understand your concern and agree, but as Stian rightly points out, this is a top-level (no pun intended) question that only those with a more intimate knowledge of the J! framework will know how to solve. I've been working with Joomla for over three years and I don't know the answer.

Believe me when I say it's a very rare occurrence when I ask for help - I much prefer to figure stuff out for myself (you remember it for next time that way) and then post about my experience on my blog or in a forum. This is why, for me, Stian's reply was absolutely perfect - it stops me wasting countless hours searching through code, and instead gives me a nudge to find the solution for myself. So, I learn something new, and there will be a record of it for anyone else who might need/want to use it in the future (I'll post a solution when I figure it out).

I could have easily Skyped Stian and I'm sure he would have shared a solution...but whats the benefit in that? Much better to share information like this I think.
Okay, here's my solution:

// Function to get parent menu titles
class getParentMenuTitle {
function getList()
{
global $mainframe;
// Get the PathWay object
$pathway =& $mainframe->getPathway();
$items = $pathway->getPathWay();
$count = count($items);
for ($i = 0; $i < $count; $i ++)
{
$items[$i]->name = stripslashes(htmlspecialchars($items[$i]->name));
$items[$i]->link = JRoute::_($items[$i]->link);
}

return $items;
}
}
$list = getParentMenuTitle::getList();
$count = count($list);
if ($count !== 0) :
$parentmenu = $list[0]->name;
$parentmenu = ereg_replace(" ", "-", $parentmenu); // replace spaces with a dash
$parentmenu = ereg_replace("[^+A-Za-z0-9-]", "", $parentmenu); // strip special characters
$parentmenu = strtolower($parentmenu); //set name to lowercase
else :
$parentmenu = "home"; // Set parentmenu to "home" if there are no items
endif;

...you can then just echo $parentmenu onto the main wrapper (or anywhere you need it to be), then add the ID/classes into CSS to do the styling.

I daresay there's a more elegant solution, but this works just as I need it to. Thanks, Stian, for the steering ;)
Can strip out the loop & the link variable, since we only need one item from the array and don't use the link:

$items[1]->name = stripslashes(htmlspecialchars($items[1]->name));

Replaces:

for ($i = 0; $i < $count; $i ++)
{
$items[$i]->name = stripslashes(htmlspecialchars($items[$i]->name));
$items[$i]->link = JRoute::_($items[$i]->link);
}
Thanks Dan and Stain - I was hoping there might be a better approach than unloading the Pathway. If not, it might be nice to think about additional functions, like this one, that would make Templating easier.

Also, might have to provide for your Home Menu item, if the pathway is set to exclude Home.

One recommendation is to use the Application object since $global mainframe will be removed in 1.6.
$app = &JFactory::getApplication();

Instead of
$global mainframe;

Then use $app instead of $mainframe (or whatever variable name you use).

I'll point to Andrew Eddie's Converting Old Extensions to Joomla 1.5 resource - his whole site is awesome.

Good question. Stian is very knowledgeable, appreciate sharing the response with everyone.
Thanks Amy. So that leaves us with:

class getParentMenuTitle {
function getList()
{
$getParent = &JFactory::getApplication();
// Get the PathWay object
$pathway =& $getParent->getPathway();
$items = $pathway->getPathWay();
$items[1]->name = stripslashes(htmlspecialchars($items[1]->name));
return $items;
}
}
$list = getParentMenuTitle::getList();
$count = count($list);
if ($count !== 0) :
$parentmenu = $list[0]->name;
$parentmenu = ereg_replace(" ", "-", $parentmenu); // replace spaces with a dash
$parentmenu = ereg_replace("[^+A-Za-z0-9-]", "", $parentmenu); // strip special characters
$parentmenu = strtolower($parentmenu); //set name to lowercase
else :
$parentmenu = "home"; // Set parentmenu to "home" if there are no items
endif;

It's pretty compact, I'm happy with that. What are the potential issues (if any) re: unloading the Pathway?
Well, maybe It's just wishful thinking on my part, to hope that a function, like the one you just created, would already be available.

It's a good question. Having professional designers in a focused space, like this, asking these types of questions can help make it easier to find helpful improvements.

Now that the Magazine is firing up again, it might be nice to have a well written article focusing on the Menu: Styling and accessing the API.

If I get a response from my Tweet, or some unlucky core developer stumbles in my way, I'll share, too. This was very helpful to me. Thanks!

RSS

Badge

Loading…

© 2012   Created by Amy Stephen.

Badges  |  Report an Issue  |  Terms of Service