0 users online. Create an account or sign in to join them.Users
Filtering Content
This is an open discussion with 14 replies, filed under Troubleshooting.
Search
I’d like to know how this works too. I’ve tried to do the same thing and failed.
I’d also like to be able to set up something like this:
www.mysite.com/portfolio/
This is my overview of the portfolio section.
www.mysite.com/portfolio/entry-a/
This is a specific entry in the portfolio section.
Can you use the same page for both? Can you take it further and include things such as tags or categories? Like this?
www.mysite.com/portfolio/category-a/
Does this help? Or Nested Conditionals in XSLT. Same thing.
yeah that is the one I think.
I think I am going to start going to your site before I go to Google from now on. :)
Good job.
Actually not sure you understood my question.
I want to go to mypage.com/products
and see products by category. and I want to also be able to go to:
mypage.com/products
and see products by materials instead. So the same url, but it shows different content.
I’m not sure how you would do that unless you were using JavaScript to view tabs that reveal different content: http://jqueryui.com/demos/tabs/
Is that what you had in mind?
Well couldn’t I pass a parameter when I click a link?
It seemed to me that you wanted the links to be identical. I was trying to figure out how you would pass a parameter with identical links. If what you are trying to do is display different results based on the category selected, a similar template should apply.
<xsl:choose>
<xsl:when test="$a">
<xsl:for-each select="/data/products/entry[category/item/@handle = $a]">
<!-- Display products with a category that matches $a -->
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:for-each select="/data/products/entry[materials/item/@handle = 'value']">
<!-- Display products of a material that matches a predefined value -->
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
I’m guessing without knowing the XML.
Yeah that looks good.
But how would I pass the value of $a?
Symphony URL Parameters: Managing Page Views
Symphony URL Parameters allow a single page template to manage several different views of the XML data. Using XSLT and some flexible URL parameters, it is possible to filter entries by different sets of categories or other forms of metadata to create nested lists.
When creating a page template, specify URL parameters to be able to control different page views, depending on the value of each URL parameter. If the URL Parameters a/b have been specified in the page template, you could display a couple links to select two different overviews.
<ul>
<li><a href="{$root}/products/categories/">View Products by Category</a></li>
<li><a href="{$root}/products/materials/">View Products by Material</a></li>
</ul>
Let’s assume that a site needs to display a list of products which can be viewed by category or by material. One strategy might be to create three sections: one for Categories and another for Materials, then a separate section for Products. The Products section could include two Select Box Link fields: one called Category linked to the Title field of the Categories section, and one called Material linked to the Title field of the Materials section. Create three data sources for the overviews that include the elements that would display on an overview page: Products, Categories and Materials.
Creating Lists with XSLT
List the products by category by first creating a list of the categories:
<h3><a href="{$root}/products/categories/">Categories</a></h3>
<ul>
<xsl:for-each select="/data/categories/entry">
<li><a href="{$root}/products/{title/@handle}/"><xsl:value-of select="title"/></a></li>
</xsl:for-each>
</ul>
A list of the materials would be similar:
<h3><a href="{$root}/products/materials/">Materials</a></h3>
<ul>
<xsl:for-each select="/data/materials/entry">
<li><a href="{$root}/products/{title/@handle}/"><xsl:value-of select="title"/></a></li>
</xsl:for-each>
</ul>
Lists of Lists
Use a named template to call a list of products for each category, and another to call a list of products for each material:
<xsl:template name="products-by-category">
<xsl:param name="category"/>
<xsl:for-each select="/data/products/entry[category/item/@handle = $category]">
<li><a href="{$root}/products/{$category}/{title/@handle}/"><xsl:value-of select="title"/></a></li>
</xsl:for-each>
</xsl:template>
<xsl:template name="products-by-material">
<xsl:param name="material"/>
<xsl:for-each select="/data/products/entry[material/item/@handle = $material]">
<li><a href="{$root}/products/{$category}/{title/@handle}/"><xsl:value-of select="title"/></a></li>
</xsl:for-each>
</xsl:template>
Products by Category
Call the “products-by-category” template to create a list of products organized by category:
<xsl:template name="products-categories">
<h3><a href="{$root}/products/categories/">Categories</a></h3>
<ul>
<xsl:for-each select="/data/categories/entry">
<li>
<a href="{$root}/products/{title/@handle}/"><xsl:value-of select="title"/></a>
<ul>
<xsl:call-template name="products-by-category">
<xsl:with-param name="category" select="title/@handle"/>
</xsl:call-template>
</ul>
</li>
</xsl:for-each>
</ul>
</xsl:template>
Products by Material
Call the “products-by-material” template to create a list of products organized by material:
<xsl:template name="products-materials">
<h3><a href="{$root}/products/materials/">Materials</a></h3>
<ul>
<xsl:for-each select="/data/materials/entry">
<li>
<a href="{$root}/products/{title/@handle}/"><xsl:value-of select="title"/></a>
<ul>
<xsl:call-template name="products-by-material">
<xsl:with-param name="material" select="title/@handle"/>
</xsl:call-template>
</ul>
</li>
</xsl:for-each>
</ul>
</xsl:template>
A Named Template to Display Entries
Create a named template for displaying each product entry:
<xsl:template name="product-entry">
<h4><a href="{$root}/products/{$a}/{title/@handle}/"><xsl:value-of select="title"/></a></h4>
<xsl:copy-of select="description/*"/>
</xsl:template>
Managing Page Views
Then, create the logic to display each view by using an xsl:choose instruction:
<xsl:choose>
<xsl:when test="$b">
<xsl:for-each select="/data/products/entry[title/@handle = $b]">
<xsl:call-template name="product-entry"/>
</xsl:for-each>
</xsl:when>
<xsl:when test="$a = 'materials'">
<!-- Display a list of materials when the URL is
http://www.example.com/products/materials/ -->
<xsl:call-template name="products-materials">
</xsl:when>
<xsl:when test="$a">
<h3>
<!-- Assuming no category will be identical to a name for a material,
this should display a single value for the matching material/category -->
<xsl:value-of select="/data/materials/entry[title/@handle = $a]/title"/>
<xsl:value-of select="/data/catgories/entry[title/@handle = $a]/title"/>
</h3>
<xsl:for-each select="/data/products/entry[materials/item/@handle = $a]">
<!-- Display products with a material that matches $a -->
<xsl:call-template name="product-entry"/>
</xsl:for-each>
<xsl:for-each select="/data/products/entry[category/item/@handle = $a]">
<!-- Display products with a category that matches $a -->
<xsl:call-template name="product-entry"/>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<!-- Display a list of categories when the URL is
http://www.example.com/products/ -->
<xsl:call-template name="products-categories">
</xsl:otherwise>
</xsl:choose>
Data Source Optimization
These templates use XSLT to filter entries. To be able to display full entries for each product, it would be best to use data source filtering to ensure that the XML output is optimized in order to keep page load times as fast as possible. With different data sources, adjust the XPath expressions to select the appropriate XML nodes.
Read more about Symphony Data Sources or refer to the Symphony documentation.
Oh sorry, I understand these methods, I think I was just thinking of a way to pass the param without having a different url each time, but on reflection I realise that it’s not really possible.
This is all good stuff though for people to learn from, thanks for the effort.
Just a quick tip, Nick, you don’t want to pass parameters that change page content without changing the URL. There are a number of SEO benefits to having the URL change and users view it as a breadcrumb of sorts. If you do the params right people can even learn to play around with them.
yeah I have gone with 2 separate pages for the 2 different types.
Hi bauhouse, am newbie
what is meant by “named template” ?
You can either have a template with a name
<xsl:template name=""></xsl:template>
or a matched template
<xsl:template match=""></xsl:template>
Create an account or sign in to comment.
I’m sure this is possible, but am I able to deliver different content to a page determined by what params?
For example, I have a products section. In this section you can view the products by category or material. I want category by default, but I want there to be a button which switches the content to show the products by material.