Checkbox to make feature products appear on homepage
Hi all,
I already created a product catalogue in Umbraco and what i wanted to achieved is put a property somewhre in the product item document type (check true/false) - and when you choose true/checked - its also publishes the product in a feature product region on homepage.
My tree node:
Home Products - Product 1 - Product 2 etc..
and when checked for example the product 1 it shows it on homepage...without the need to add a node under home.
Clear enough??
Do i have to create another XSLT for this...I've done something similar for my news but we needn.t need to check its just shows the 3 last added from my news list on homepage also..
You'll have to create another xslt for this. it will be very close to your news example. The only thing that will change will be the select in your for-each loop
Note: Change ProductsArea to the alias of your "Products" page document type, and same for Product. Change isFeatured to the alias of your checkbox property.
Then you can insert this macro into your template where you want the featured products to appear.
Hopefully this gets you started, feel free to post back any questions.
Do you think its a problem with old/new schema syntax??...I am on Umbraco v 4.6.1 or I am doing something wrong (by the way i kept isFeatured as the alias of my checkbox property.)
The Offers node is under my default page node, like this
Content default - Company Profile - Offers
When using <textarea><xsl:copy-of select="$currentPage/ancestor::root/Offers"/></textarea> I get only the footer html code of my page in the textbox....and when removing /Offers i get the html of all pages...a bit weird?
Where do you exactly put the <textarea>.... in the XSLT...perhaps that why i get those results...
Hi Tom....im so silly...figures it out myself...though you put me on the right track, I just had to add default node to my for-each select...like this:
Glad to hear it! FYI, if you are seeing HTML from the footer of your template/page in the textarea it usually means the textarea's content was blank, meaning the XPath resulted in no results. When you removed /Offers you (should) have seen the Umbraco XML of all the pages of your site, which should help you figure out why it wasn't working. In this case I guess everything was wrapped in a <default> node? Anyway, glad it's working now!
Checkbox to make feature products appear on homepage
Hi all,
I already created a product catalogue in Umbraco and what i wanted to achieved is put a property somewhre in the product item document type (check true/false) - and when you choose true/checked - its also publishes the product in a feature product region on homepage.
My tree node:
Home
Products
- Product 1
- Product 2 etc..
and when checked for example the product 1 it shows it on homepage...without the need to add a node under home.
Clear enough??
Do i have to create another XSLT for this...I've done something similar for my news but we needn.t need to check its just shows the 3 last added from my news list on homepage also..
Please guide me through this.
Thks
Sam.
You'll have to create another xslt for this. it will be very close to your news example. The only thing that will change will be the select in your for-each loop
Hi Sam,
Yes, you'll want to use a Macro for this (whether XSLT, Razor, or .NET). XSLT is probably simplest, for me anyway.
Create a new XSLT File in the Developer section and leave the "Create macro" checkbox checked. For your code you could use something like:
Note: Change ProductsArea to the alias of your "Products" page document type, and same for Product. Change isFeatured to the alias of your checkbox property.
Then you can insert this macro into your template where you want the featured products to appear.
Hopefully this gets you started, feel free to post back any questions.
-Tom
Hi Tom,
Thks...I've tried this out,created the macro and inserted it homepage...still renders nothing..
MY CODE:
<xsl:for-each select="$currentPage/ancestor::root/Offers/OfferItem [@isDoc][string(isFeatured) = '1'][position() < 3]">
<!--special offer boxes -->
<div class="SpOfferListBox">
<div class="SpOfferTit"><xsl:value-of select="offerName"/></div>
<div class="SpOfferImg"><a href="#"><img src="{offerPhoto}" width="180" height="140" alt="{@nodeName}" /></a></div>
<div class="SpOfferSum"><xsl:value-of select="offerDescription" disable-output-escaping="yes"/></div>
</div>
</xsl:for-each>
Do you think its a problem with old/new schema syntax??...I am on Umbraco v 4.6.1 or I am doing something wrong (by the way i kept isFeatured as the alias of my checkbox property.)
Sam.
Hi Sam,
This example is using the new schema, which you should be using unless you explicity told Umbraco to use the old schema?
Is the Offers node directly under the Content root?
A good way to debug is to dump out the XML in a textbox so you can see the XML it's working with.
<textarea><xsl:copy-of select="$currentPage/ancestor::root/Offers"/></textarea>
Try that, do you get <Offers ...><OfferItem ...> nodes? If not get rid of /Offers and see what you get.
-Tom
Hi Tom..yes Im usint the new schema...
The Offers node is under my default page node, like this
Content
default
- Company Profile
- Offers
When using <textarea><xsl:copy-of select="$currentPage/ancestor::root/Offers"/></textarea> I get only the footer html code of my page in the textbox....and when removing /Offers
i get the html of all pages...a bit weird?
Where do you exactly put the <textarea>.... in the XSLT...perhaps that why i get those results...
Anyway here is mu full XSLT
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxml="urn:schemas-microsoft-com:xslt"
xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets"
exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:param name="currentPage"/>
<xsl:template match="/">
<!-- The fun starts here -->
<xsl:for-each select="$currentPage/ancestor::root/Offers/OfferItem [@isDoc][string(isFeatured) = '1'][position() < 3]">
<!--special offer boxes -->
<div class="SpOfferListBox">
<div class="SpOfferTit"><xsl:value-of select="offerName"/></div>
<div class="SpOfferImg"><a href="#"><img src="{offerPhoto}" width="180" height="140" alt="{@nodeName}" /></a></div>
<div class="SpOfferSum"><xsl:value-of select="offerDescription" disable-output-escaping="yes"/></div>
</div>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Hope that can clear things up...
Sam
Hi Tom....im so silly...figures it out myself...though you put me on the right track, I just had to add default node to my for-each select...like this:
<xsl:for-each select="$currentPage/ancestor::root/default/Offers/OfferItem [@isDoc][string(isFeatured) = '1'][position() < 3]">
Works like a charm now...
Thanks to you...
Sam.
Glad to hear it! FYI, if you are seeing HTML from the footer of your template/page in the textarea it usually means the textarea's content was blank, meaning the XPath resulted in no results. When you removed /Offers you (should) have seen the Umbraco XML of all the pages of your site, which should help you figure out why it wasn't working. In this case I guess everything was wrapped in a <default> node? Anyway, glad it's working now!
-Tom
is working on a reply...