Im listing a number of products on my page - I've created a xslt and macro for this - But cant get it to output anything in the for each loop? If i type in something outside the foreach loop it renders?
the Alias that is in the document type i want is "ProdCat"
Also the current page calls... am I correct in thinking they are to render data within the iteration ?for example if $currentPage/@nodeName is supposed to be one of the ProdCat nodes then you would just use
you only refer to your immediate children (and not descendants).
You could add a cointent-picker argument/property to your macro to identify the "Produkt" node, and then refer to child nodes of this selected node. Otherwise (if you always know the position of the "Produkt"-node) you can refer to it absolutely using e.g. the root node of the content tree (you can get this using the library function GetXmlAll())
Im not sure of what you mean by adding a content picker, and identify the Produkt node? It's my first site in Umbraco so im not that exp with the system... I've watched all of the videos that they have in umbraco, but there's nothing that relates to this problem :(
If it's in your master template, you probably want the product categories to appear on all pages, no matter where you are in the structure. Tommy's solution is quite close, you could also:
To add a content picker proprty, go to your Macro definition in the Developer section.
In the right pane, click on the "Parameters" tab. Here you can enter name and alias for you new parameter, and then select "contentPicker" in the drop down.
When adding a macro to a template you will be prompted to select a node in the content tree - in your case select the Produkt-node.
In your xslt you create a variable selecting the paramter value, and use that as your reference for the Produkt-node. Something like this:
Hmm, guess $currentPage is referring to itself (The page im at, Frontpage)? - Could this be the problem, because the Product Categories is created on another page, under the page "Products"!
Whats wrong with my for each?
Im listing a number of products on my page - I've created a xslt and macro for this - But cant get it to output anything in the for each loop? If i type in something outside the foreach loop it renders?
the Alias that is in the document type i want is "ProdCat"
Here's the 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"/>
<!-- Input the documenttype you want here -->
<xsl:variable name="documentTypeAlias" select="string('weblogItem')"/>
<xsl:template match="/">
<xsl:value-of select="@nodeTypeAlias" disable-output-escaping="yes"/>
<!-- The fun starts here -->
<xsl:for-each select="$currentPage/node [@nodeTypeAlias = 'ProdCat' and string(data [@alias='umbracoNaviHide']) != '1']">
<div class="prodcatbox">
<h2><a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="data [@alias = 'ProdCatName']"/></a></h2>
<div class="boxtop"><!----></div>
<div class="boxmiddle">
<xsl:if test="$currentPage/data [@alias='Media'] != ''">
<div class="catimage">
<img alt="{$currentPage/@nodeName}" title="{$currentPage/@nodeName}" class="cat_image">
<xsl:attribute name="src">
<xsl:value-of select="umbraco.library:GetMedia($currentPage/data [@alias='Media'], 'false')/data [@alias = 'umbracoFile']" />
</xsl:attribute>
</img>
</div>
</xsl:if>
<div class="catsummary">
<xsl:value-of select="data[@alias = 'ProdCatShortDesc']"/>
</div>
</div>
<div class="boxbottom"><!----></div>
</div>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
I believe you don't need the and
[@nodeTypeAlias = 'ProdCat' and string(data [@alias='umbracoNaviHide']) != '1']
becomes
[@nodeTypeAlias = 'ProdCat' ] [string(data [@alias='umbracoNaviHide']) != '1']
Also the current page calls... am I correct in thinking they are to render data within the iteration ?for example if $currentPage/@nodeName is supposed to be one of the ProdCat nodes then you would just use
@nodeName
ignore the AND post both will work.
Hmm, still cant get it to work.....
What i want is to display my Product Categories on my frontpage - So i created an xslt file, of the type: List Subpages by Document Type.
The Document Type alias is: "ProdCat" - But i cant get it to display anything at all??
My "sitetree" looks like:
Frontpage
About
News
Produkt
- Productcategory1
- Product1
- Productcategory2
My xslt is now:
<?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/node [@nodeTypeAlias = 'ProdCat']">
<div class="prodcatbox">
<h2><a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="data [@alias = 'ProdCatName']"/></a></h2>
<div class="boxtop"><!----></div>
<div class="boxmiddle">
<xsl:if test="$currentPage/data [@alias='Media'] != ''">
<div class="catimage">
<img alt="{$currentPage/@nodeName}" title="{$currentPage/@nodeName}" class="cat_image">
<xsl:attribute name="src">
<xsl:value-of select="umbraco.library:GetMedia($currentPage/data [@alias='Media'], 'false')/data [@alias = 'umbracoFile']" />
</xsl:attribute>
</img>
</div>
</xsl:if>
<div class="catsummary">
<xsl:value-of select="data[@alias = 'ProdCatShortDesc']"/>
</div>
</div>
<div class="boxbottom"><!----></div>
</div>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Hi Nicky, for what node in your sitetree have you added the macro-call (directly or using a template)?
It's in my template "Master" like this:
<%@ Master Language="C#" MasterPageFile="/umbraco/masterpages/default.master" AutoEventWireup="true" %>
<asp:Content ContentPlaceHolderID="ContentPlaceHolderDefault" runat="server">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"[]>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="head" runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title><asp:placeholder runat="server"><umbraco:Item runat="server" field="pageName" /> - <umbraco:Item runat="server" field="siteName" recursive="true" /></asp:placeholder></title>
<link rel="stylesheet" type="text/css" href="/css/markings.css" />
</head>
<body>
<div id="container">
<div class="wrapper">
<div id="top">
<div class="servicemenu">
<img src="/images/addfavorite.gif" alt="Tilføj som favorit" title="Tilføj som favorit" />
<img src="/images/print.gif" alt="Print siden" title="Print siden" />
<img src="/images/rss.gif" alt="RSS" title="RSS" />
</div>
</div>
<div id="header">
<div class="logo">
<a href="/" title="Markings"><img src="/images/blank.png" width="130" height="95" alt="Markings" title="Markings" /></a>
</div>
<div class="headerelements">
Punchlines
</div>
</div>
<div id="menubar">
<div id="menu">
<umbraco:Macro Alias="RunwayTopNavigation" runat="server" />
</div>
<div id="search">
Søgning her
</div>
<div class="reset"><!----></div>
</div>
<div id="maincontent">
<div class="maincnttop"><!----></div>
<div class="content">
<form id="RunwayMasterForm" runat="server">
<asp:ContentPlaceHolder ID="RunwayMasterContentPlaceHolder" runat="server"></asp:ContentPlaceHolder>
</form>
<umbraco:Macro Alias="ProdCats" runat="server"></umbraco:Macro>
</div>
</div>
</div>
<div id="footer">
</div>
</div>
</div>
</body>
</html>
</asp:content>
By using a reference like this:
you only refer to your immediate children (and not descendants).
You could add a cointent-picker argument/property to your macro to identify the "Produkt" node, and then refer to child nodes of this selected node. Otherwise (if you always know the position of the "Produkt"-node) you can refer to it absolutely using e.g. the root node of the content tree (you can get this using the library function GetXmlAll())
>Tommy
For easy testing you script you can try:
but this would be be a nice "real" solution as you would be searching all descendants of the current page - not only the Produkt page
But even if i replace my for-each with:
It still wont output anything? :(
Im not sure of what you mean by adding a content picker, and identify the Produkt node? It's my first site in Umbraco so im not that exp with the system... I've watched all of the videos that they have in umbraco, but there's nothing that relates to this problem :(
what node is your $currenPage referring to?
If it's in your master template, you probably want the product categories to appear on all pages, no matter where you are in the structure. Tommy's solution is quite close, you could also:
which will work from any page, regardless of the level or current page you're browsing.
Cheers,
/Dirk
To add a content picker proprty, go to your Macro definition in the Developer section.
In the right pane, click on the "Parameters" tab. Here you can enter name and alias for you new parameter, and then select "contentPicker" in the drop down.
When adding a macro to a template you will be prompted to select a node in the content tree - in your case select the Produkt-node.
In your xslt you create a variable selecting the paramter value, and use that as your reference for the Produkt-node. Something like this:
See more about macros here:http://umbraco.org/documentation/books/macro-parameters-syntax/an-overview-of-all-the-macro-parameters
Hmm, guess $currentPage is referring to itself (The page im at, Frontpage)? - Could this be the problem, because the Product Categories is created on another page, under the page "Products"!
This is exactly why you do not get any nodes when doing a search on immediate children of the currentpage.
Instead, use the getxmlall() funtion as your base-reference instead of $currentpage as Dirk suggests, or add a macro property as described above.
is working on a reply...