3 users online. Create an account or sign in to join them.Users
How to remove duplicates from category list?
This is an open discussion with 8 replies, filed under General.
Search
There are several ways to do this:
- You could use a separate Section named “Categories” into which you create a new entry for each Category (allowing you to store additional meta data should you wish). You could link the two with a Select Box Link field (which links using IDs rather than string values, so the relationship stays intact even if a category name changes slightly). You then build the list of Categories with a DS from that section.
- Keep your existing DS but choose “Category” as the value for the “Group By” dropdown in the Data Source editor. In the XML you’ll then get a node for each category, then the References within it, so you can simply iterate over each distinct Category.
- You could use an XPath
axisto select “distinct” categories using thepreceding-siblingorfollowing-siblingaxis (example) - If you’re brave, keep your DS as-is and use the Muenchian method of grouping in XSLT (about as complex as XSLT generally gets!)
- Use the Section Schemas extension which can output the list of categories in the XML (it reflects your section structure in XML, so you get all of your field setup meta data)
I think the simplest method (that requires the least effort) is grouping in your DS itself (#2).
Hey Nick,
Thanks a lot for your help. I kind of had a hunch that I would have to create another section here. I decided to go with your first solution and it works great: Link to website
All references can now be filtered by category.
But what if I want to show the 3 latest references on the root site? I created another data source named “latest-references” for this but it seems cumbersome to me because it is inherited by each category page. What would be a better way to achieve this?
You can use something like
<xsl:apply-templates select="xpath/to/entry[position() <= 3]"/>
on your root site.
Hey klafertief,
Thanks for your hint.
The idea is good but it’s not working for me because my datasource “References” is filtered by category. If no category is provided, I get an empty screen. Is there any way to circumvent this? This is my code:
<xsl:choose>
<xsl:when test="$category != ''">
<xsl:apply-templates select="references/entry" />
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="references/entry[position() <= 3]"/>
</xsl:otherwise>
</xsl:choose>
<xsl:template match="references/entry">
<h2><xsl:value-of select="title"/></h2>
<p><xsl:value-of select="text"/></p>
</xsl:template>
Thanks for any help.
The XSL looks correct. Are there entries in the unfiltered XML debug page? What does your datasource filter look like?
Hey klaftertief,
I filter my datasource by $category which works fine, except when no $category is provided.
When I remove the filter from the datasource, the last three entries appear in the XML as planned.
But of course the filter no longer works then… :-(
Hm, the filter should be ignored when the parameter is empty.
Hey klaftertief,
Sorry, you are right of course. I just realised that I should better have left the “Required URL Parameter” field empty.
I was so used to it that I completely forgot to empty it. Silly me.
So it finally works as intended. Thanks a lot for your help!!
Create an account or sign in to comment.
Hello,
I am currently building my first website with Symphony and I got stuck.
I want to build a portfolio website where each “reference” can be allocated a “category”.
So to achieve this I created a section “References” with a select box “Category”. I then manually created a range of static options.
I then created a datasource named “Categories” and a category menu on my page:
<xsl:template match="categories/entry"> <li> <a href="{$root}/references/{category/item/@handle}"> <xsl:value-of select="."/> </a> </li> </xsl:template>The problem with this is that each category is now returned not only once, but depending on how many references there are in that category.
Can anybody tell me how to display each category name only once?
Thanks for any help…