I have listed related products (other products in the category) on the product page, with the code below.. But I would like to separate it to its own xslt file (relatedProducts.xslt), and the including the code on the product page (product_product.xslt) ...
If I'm right I should wrap that code in a template <xsl:template match="RelatedProducts"> .... </xsl:template> in the relatedProducts.xslt .. and the somehow include that template where I want it in the product_product.xslt.. How do I do this?
<!-- I make the name() = 'Product' check here to force umbraco to save the page. Otherwise it cheats and throws errors all over the place. --> <xsl:apply-templates select="$currentPage [name() = 'Product']" /> </xsl:template>
<xsl:template match="Product" > <!-- Code for the product here: title, description, price, images, variants etc. --> <div class="clearBoth"><xsl:text> </xsl:text></div> <xsl:call-template name="RelatedProducts" /> </xsl:template>
Include xslt in another xslt
Hi..
I have listed related products (other products in the category) on the product page, with the code below..
But I would like to separate it to its own xslt file (relatedProducts.xslt), and the including the code on the product page (product_product.xslt) ...
If I'm right I should wrap that code in a template <xsl:template match="RelatedProducts"> .... </xsl:template> in the relatedProducts.xslt .. and the somehow include that template where I want it in the product_product.xslt..
How do I do this?
Bjarne
Hi Bjarne,
I wrote an article on that here: http://pimpmyxslt.com/articles/include-or-import/
/Chriztian
Hi Chriztian..
I looked at your article and looked around on the forum and came up with this:
relatedProducts.xslt
and then in my product_product.xslt where I have included the relatedProducts.xslt and the called the template below the product.
It seem to work and save the files without errors and also seem to be displayed just as before: http://sub.ak-security.dk/da/shop/category-b/product-b2.aspx
Is it the right way I have done it?
Bjarne
I get a small error with:
I need them in both files, but I'll then have an error when saving the files..
So right now I have removed them from relatedProducts.xslt..
is there any way I can include them in the relatedProducts.xslt without getting an error saying it's duplicated..
Bjarne
Hi Bjarne,
Yes, it's an error to include/import a global variable/parameter with the same name as an existing - but it's fixable...
The best and most flexible way of doing this, is to add them as parameters to the template:
- and then send in the values when calling it:
This way, you've actually decoupled the template from its surroundings and made it easier to test - win! :-)
/Chriztian
Thanks.. that fixed it..
I also noticed that when changing something in relatedProducts.xslt I have to save product_product.xslt before I can see the changes..
But I think I read something about XSLTouch fix this problem..?
Bjarne
Do you know why the images is moves a bit down and to left here: http://sub.ak-security.dk/da/shop/category-a/product-a3.aspx ... it should stay on the right as it is here: http://sub.ak-security.dk/da/shop/category-b/product-b3.aspx
The div with class thumb_wrapper is moved inside the productContent div.. but it should be outside that div..
When I remove the include link and the called template from the product_product.xslt it's shown fine with the images on the right..
Bjarne
Okay.. the product description div was self-closing, when the product description was empty.. but I fixed it with adding a forced space with xsl:text ... it could be xsl:comment, xsl:value-of select=" " as well: http://our.umbraco.org/wiki/how-tos/xslt-useful-tips-and-snippets/stop-html-tags-from-self-closing
Bjarne
is working on a reply...