Generate navigation from selected checkbox list values from child nodes
I'm trying to grab the selected checkbox list datatype values from child nodes, and generate navigation links for these values that pass the value into a query string.
I have the following node structure (Product Sub Type is what I'm trying to grab):
So for example, on the Womens page, I'd like to have the following navigation:
Necklaces >
<a href="?Gold">Gold</a>
<a href="?Diamond">Diamond</a>
I can get a simple list of the selected values using this:
This is taken from an old schema site. preIDProduct is the ID of the Data Type, the logic being that GetPreValues returns all of the options, and the template preValue checks to see if it has been used, if it has it outputs the option value.
Thanks Richard. I always appreciate the responses I get on this forum! Your code is giving me a list of all possible checkbox list values, not just the ones selected. Is that what it should be doing? For the purposes of this navigation, I only want the ones that were selected on the child nodes.
Here's what I get with your code:
What I want to get is, for example, just "Gold" and "Diamonds" under Necklaces, because they are the only two options selected on the child nodes of Necklaces.
We use this logic to only list checked items on a site that we created, very similar to what you want to do. I would check the workings of the if statement within the match preValue template. As this template is called for every checkbox option, the /data[@alias='sector'] is the alias of the checkbox property on the child page.
There are two subtle things wrong (from what I can see):
In the preValue template you forgot to use $currentPage in the test (all selections are relative to the element in the match attribute) - but then you shouldn't actually get any output at all, which led to the missing mode attribute on the template, so you need to either remove the mode="sector" from the template *or* add the mode in the apply-templates instruction.
In fact, you could just change the preValue template to this:
With this code, I get a very funky output, without any values from the checkboxlist (productSubType). I basically just get the first level nodes, nested incorrectly:
If I add "mode="productSubType"" to the preValue template, I get all possible values of the checkboxlist, like I was before, without sorting out selected values.
Still stuck on this.. anyone out there have any ideas? Me and Tagging and Umbraco never get along... this is the second project where I got stuck on this same scenario.
Only catch here is if you've got tags called "Ring" and "Gold Ring" - then you'll need to add some commas to the tests because "Gold Ring" will be printed every time "Ring" was selected too.
For posterity's sake, here's the working code, though I'm still trying to figure out how to get the <xsl:value-of select="umbraco.library:NiceUrl(@id)"/> working correctly in the preValue template (it's giving the value of the current page, not the current node being processed -- I guess I want the $node ID value, but not sure how to get that correctly).
Generate navigation from selected checkbox list values from child nodes
I'm trying to grab the selected checkbox list datatype values from child nodes, and generate navigation links for these values that pass the value into a query string.
I have the following node structure (Product Sub Type is what I'm trying to grab):
So for example, on the Womens page, I'd like to have the following navigation:
Necklaces >
I can get a simple list of the selected values using this:
<xsl:variable name="values" select="concat(./*/productSubType,',')"/>
But I need to break them out for the navigation.. not sure how to best do that, without getting duplicates.
Laura,
The following should give you a list of the used checkbox list items:
This is taken from an old schema site. preIDProduct is the ID of the Data Type, the logic being that GetPreValues returns all of the options, and the template preValue checks to see if it has been used, if it has it outputs the option value.
Richard
Thanks Richard. I always appreciate the responses I get on this forum! Your code is giving me a list of all possible checkbox list values, not just the ones selected. Is that what it should be doing? For the purposes of this navigation, I only want the ones that were selected on the child nodes.
Here's what I get with your code:
What I want to get is, for example, just "Gold" and "Diamonds" under Necklaces, because they are the only two options selected on the child nodes of Necklaces.
Laura,
We use this logic to only list checked items on a site that we created, very similar to what you want to do. I would check the workings of the if statement within the match preValue template. As this template is called for every checkbox option, the /data[@alias='sector'] is the alias of the checkbox property on the child page.
Richard
Gosh, I must be dense, but I'm still not getting it. I didn't change anything in your code other than the alias & ID of the checkbox datatype.
I tried this, which gives me everything that was selected on the child nodes, but it gives me duplicates:
<xsl:for-each select="./*/productSubType">
<xsl:value-of select="."/>
</xsl:for-each>
But this gives me a long list of duplicates: Gold,DiamondGold,DiamondGold,DiamondGold, etc.
I want to lump them all together. I wish I could figure this out!
This is what I have thus far, based on the code given, but no luck:
Hi Laura,
There are two subtle things wrong (from what I can see):
In the preValue template you forgot to use $currentPage in the test (all selections are relative to the element in the match attribute) - but then you shouldn't actually get any output at all, which led to the missing mode attribute on the template, so you need to either remove the mode="sector" from the template *or* add the mode in the apply-templates instruction.
In fact, you could just change the preValue template to this:
(Depending on which page you call it from you may need to change the XPath a little)
/Chriztian
Thanks Chriztian. I changed my code to this, but it's still not working:
With this code, I get a very funky output, without any values from the checkboxlist (productSubType). I basically just get the first level nodes, nested incorrectly:
If I add "mode="productSubType"" to the preValue template, I get all possible values of the checkboxlist, like I was before, without sorting out selected values.
Still stuck on this.. anyone out there have any ideas? Me and Tagging and Umbraco never get along... this is the second project where I got stuck on this same scenario.
Hi Laura,
Could you do a <xsl:copy-of select="$currentPage/productSubType" /> on one of the pages that has this one defined?
And if you could do another one: <xsl:copy-of select="umbraco.library:GetPreValues($preIDProduct)" />
(If you're doing it in the XSLTVisualizer, rememeber to wrap a <textarea> around the copy-of so the XML doesn't get mangled by the tool)
- We'll make it work for sure.
/Chriztian
Hi again,
Did a quick test to see what the CheckboxList actually saves - I think (without having seen the XML) you'll need to do the following:
In the lines where you apply templates to the preValues, send the current node of the surrounding for-each along:
- and receive it in the template - *and* fix the error in the contains() test:
Only catch here is if you've got tags called "Ring" and "Gold Ring" - then you'll need to add some commas to the tests because "Gold Ring" will be printed every time "Ring" was selected too.
/Chriztian
Chriztian, you are amazing! It works beautifully!
For posterity's sake, here's the working code, though I'm still trying to figure out how to get the <xsl:value-of select="umbraco.library:NiceUrl(@id)"/> working correctly in the preValue template (it's giving the value of the current page, not the current node being processed -- I guess I want the $node ID value, but not sure how to get that correctly).
Great, Laura
You should be able to just do what you said, i.e.: NiceUrl($node/@id)
/Chriztian
Perfecto! I can't tell you how much I appreciate your help.
is working on a reply...