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

"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."

Yep, you're right - I never thought of it like that. And the same technique can be used for much more than just styling some links - some real flexibility in layouts based on the top-level menus (I've done similar stuff with WordPress & it's category ids).

Keep us posted.

Dan
Gergő Erdősi responded to my Tweet with a solution I was hoping to see!

$id = JSite::getMenu()->getActive()->tree[0];

Now, that's what I love about Joomla! development. That'll get you your Top Level Item ID. Sheer elegance. W00t!
LOL, that's incredible - didn't I say it would be something simple?! :)

Much better than my schoolboy effort ;)

Thanks Amy!

Dan
Thank you for bringing this issue forward, and to Gergo for sharing a bit of his brilliance. He has been part of the Joomla! 1.6 Release Team, an obvious excellent choice. He also said he might join us here soon, which would be very good for us :)
Oooo. Fancy. I like it.
"This is another reason we need better documentation. As a template designer, I regulary have had these kind of struggles. There are a lot of secrets kept by the devs (not on purpose of course) at the moment ;)"

100% agree, and I often have the same problem. It's even more frustrating because I know (almost for a fact) that the expression I want to use exists, the problem is I don't know what it is and cannot find the answers that I need.

This solution is a prime example:

JSite::getMenu()->getActive()

I've used many times (almost every time) in a template, and my solution was literally a handful of characters out of reach. I'm sure this information exists somewhere but it's probably buried deep in some J! dev wiki or something.

There are loads of Drupal, WordPress & ExpressionEngine cheat-sheets (I have them stuck all over my pinboard in the office) listing all sorts of useful template expressions that can be used, but I've never seen anything decent for Joomla, which is a shame.

I guess one of the problems is that the devs who know this sort of information don't make templates, and similarly, template devs who know the information that's needed don't know have that deep knowledge of the J! framework.

Perhaps this is a good starting point for a new discussion - after all, we have some amazing representatives from both sides of development - template coders and developers - I'm sure between us we could probably produce a list of common template reqs and the solutions to them.

/daydream
Have a look here, it has all the ingredients to do magical stuff :-)

http://www.jfoobar.org/labs/code-snippets/289-snippet-layout-switch...
Very cool - thanks!
I missed your very good daydream, which you should not end!

We have a Joomla! 1.6 Template Guide group. It might make sense for us to put heads together and try to do something that would be helpful for us - reasonably small - and create a cheat sheet. If you have copies of this type of thing for other projects, it could be used to help us build a "here's what our cheat sheet should explain." (A sort of cheat sheet for a cheat sheet...).

Funny how you point out you were within a few keystrokes of the answer. So true. We do waste time not knowing the smallest things, don't we?

It's always hard to initiate these types of doc projects because no one has time. But maybe if we do it for us and we keep it small, then we could dream *a little bit at a time*.
Arno is a Joomla! designer/UX idol. He has more tricks in his bag then I will hope to have in a lifetime. His processes and approaches are very well developed. Shows in his work.

RSS

Badge

Loading…

© 2012   Created by Amy Stephen.

Badges  |  Report an Issue  |  Terms of Service