I'm stuck in my own way of thinking when trying to create a multilevel navigation menu.
I want the final result to behave like this:
Home (clickable, takes us to the home page) Page 1 (Anchor link (#), only child nodes takes us further) -- Page 1a (clickable, takes us to Page 1a) -- Page 1b (clickable, takes us to Page 1b) Page 2 (Anchor link (#)) -- Page 2a (clickable) -- Page 2b (clickable) Page 3 (clickable, takes us to Page 3) Page 4 (clikcable, takes us to Page 4)
So what I want to do is basically to check if a node has any child nodes. If it does, render a link to # instead of the child's NiceUrl.
If a node doesn't have any child nodes, render a link to the nodes NiceUrl.
The only 'trick' here is knowing that XSLT will not generate duplicate attributes, so first we put the standard NiceUrl() link in the href attribute, and then we check for child nodes - if present, we redefine the href attribute by putting a hash in there.
(If you need the security stuff from the "drawNodes" version, you should be able to add them back in.)
That expression is actually only used when developing locally - I create an XML file to mimic the Umbraco XML when answering posts like these, and then I use the select attribute on the param element to "fake" the $currentPage parameter when transforming locally. Though I usually delete it again before posting, it's safe to leave it in because it's only used as a default value if none gets assigned (which Umbraco does upon transformation).
So in this specific instance, I've faked a "Website" document at level 1 with at least 4 "Textpage" documents below it - the expression selects the 4th of those as $currentPage.
It's so much faster to do it this way, than having to log in to an Umbraco site and do the tweaking.
multi level menu navigation with top level anchor
Hello my fellow Umbracoholics,
I'm stuck in my own way of thinking when trying to create a multilevel navigation menu.
I want the final result to behave like this:
Home (clickable, takes us to the home page)
Page 1 (Anchor link (#), only child nodes takes us further)
-- Page 1a (clickable, takes us to Page 1a)
-- Page 1b (clickable, takes us to Page 1b)
Page 2 (Anchor link (#))
-- Page 2a (clickable)
-- Page 2b (clickable)
Page 3 (clickable, takes us to Page 3)
Page 4 (clikcable, takes us to Page 4)
So what I want to do is basically to check if a node has any child nodes. If it does, render a link to # instead of the child's NiceUrl.
If a node doesn't have any child nodes, render a link to the nodes NiceUrl.
The code I have is as follows:
But it renders a link to every page. I'm sure the solution is simple but I cannot for my life figure out what I'm missing.
Any suggestions?
Hi Emil,
It's really not that tricky - starting from scratch, here's how I'd do it:
/Chriztian
Got a question...
How does the "/root/Website/Textpage[4]" expression work? What's it referencing? Never seen this sort of thing before in other Umbraco XSLT.
I like the look of this, seems pretty efficient to me, just wish my dumb brain could understand what's going on :)
Thanks,
Barney
Hi Barney - well spotted :-)
That expression is actually only used when developing locally - I create an XML file to mimic the Umbraco XML when answering posts like these, and then I use the select attribute on the param element to "fake" the $currentPage parameter when transforming locally. Though I usually delete it again before posting, it's safe to leave it in because it's only used as a default value if none gets assigned (which Umbraco does upon transformation).
So in this specific instance, I've faked a "Website" document at level 1 with at least 4 "Textpage" documents below it - the expression selects the 4th of those as $currentPage.
It's so much faster to do it this way, than having to log in to an Umbraco site and do the tweaking.
/Chriztian
Cheers Chriztian, I understand now.
Got one more question for you though :)
How could I stop it replacing the href with # on parent nodes beyond the 2nd level nodes?
I thought something like this might do it, but doesn't work and it's bending my tiny brain...
Thanks,
Barney
Actually just got it working with this... but please tell me if you know a tidier way of doing:
is working on a reply...