Please can anyone tell me how to have that $fieldName work as intended, so I can pass "s1", "s2" etc in and have that same check made?
The reason for this is that my site has three "modes", and depending on what mode the user is in they can see only pages which have content relevant to that mode. I can switch the content itself ok, it's just getting the menu to match where content actually is which is causing me some fun.
I could not make it work with the "not" syntax, so I flipped it to a positive check as you see in the last clause there, and that works fine. The menu only shows pages which have content for the specific mode (it's a sport).
Ah, the field is actually "Rich Text" content - the idea is that if they put any content for this sport on this page, then the page appears in the menu. The content is delivered from the Template (master page), but the menu is derived from the XSLT. So the check for empty string is what I think I need. It works as expected.
---
I'm having a different problem with it, which is that my setting for "sport" is actually stored in session backed off in a cookie. I'm trying to pass that into the macro, with the following results:
Pass it as a straight macro parameter (from the Master Page c#). Doesn't work, it's not parsed at all. I can't get a value into a Macro from c# I think.
Pass it in the cookie. That works (I can read the value), but I'm "one step behind" in the life cycle with it. So the problem is that when the value changes the cookie isn't actually set until after that XSLT is processed. I tried setting it in OnInit, but that doesn't seem to help. So that almost works.
Try to access Session and pull the value from there. I will look at this.
A final option would be to dump the XSLT and just write a C# menu user control. Assuming I can get the node XLM somehow then that's the same as hacking a standard asp.net sitemap around so I can't see why that would not work,
Just because people search for stuff and will land here - the *final* (promise :-) real check for that would be to use the normalize-space() function - because (and this is especially true for Rich Texts) it's easy to end up with a field containing only whitespace or, say, three empty <div>'s or <p>'s — and you'd have no clue why stuff isn't working when looking at the field. Here's how:
For the Session/Cookie thing: - Please create a new post - we'll have a much better question+answer rate (and searchability) if we confine a post to a single topic.
normalize-space: crunch whitespace, sounds like a good idea - thanks. These WYSIWYG editors do leave lots of garbage html in there, so that is a good idea. I stuck that it and it works - I'll start another thread for the related issue, I have done more research on that now.
Macro for menu with parameter, display item only if content present
I have some XSLT which generates my menu. It hides from the menu pages which have no content in field "s1". This works:
Please can anyone tell me how to have that $fieldName work as intended, so I can pass "s1", "s2" etc in and have that same check made?
Thanks in advance for any help...
Hi philw,
If I understand your quistion right you only want content to be printed if the parameter has a value.
I dont know what markup you have in for-each statement, but I think it is a unordered list, with some list items in.
And only want the list elements to be printed if the paramter has a value right? If so you could try this:
I don´t hope I am completely misunderstood your question.
/Dennis
Hi philw,
You can do that using the name() function - like this:
/Chriztian
Perfect, thank you both.
This is a slight variation on the second of those, and it works perfectly. This is the actual code which works (not simplified as above).
I could not make it work with the "not" syntax, so I flipped it to a positive check as you see in the last clause there, and that works fine. The menu only shows pages which have content for the specific mode (it's a sport).
Job done, thanks!
Hi philw,
Yes, of course — I didn't catch that you were taking the ones with the property checked (instead of unchecked as it always is with umbracoNaviHide).
So to be safe from surprises, you should change it to actually test for that, instead of the fuzzy "not equal to <empty string>":
/Chriztian
Ah, the field is actually "Rich Text" content - the idea is that if they put any content for this sport on this page, then the page appears in the menu. The content is delivered from the Template (master page), but the menu is derived from the XSLT. So the check for empty string is what I think I need. It works as expected.
---
I'm having a different problem with it, which is that my setting for "sport" is actually stored in session backed off in a cookie. I'm trying to pass that into the macro, with the following results:
Okayyy :-)
Just because people search for stuff and will land here - the *final* (promise :-) real check for that would be to use the normalize-space() function - because (and this is especially true for Rich Texts) it's easy to end up with a field containing only whitespace or, say, three empty <div>'s or <p>'s — and you'd have no clue why stuff isn't working when looking at the field. Here's how:
For the Session/Cookie thing: - Please create a new post - we'll have a much better question+answer rate (and searchability) if we confine a post to a single topic.
/Chriztian
normalize-space: crunch whitespace, sounds like a good idea - thanks. These WYSIWYG editors do leave lots of garbage html in there, so that is a good idea. I stuck that it and it works - I'll start another thread for the related issue, I have done more research on that now.
is working on a reply...