Why not pass in the doc type as a parameter of the macro, so you can reuse the macro for all doc types? Or, as you're wanting to use it from a template, take a look at uQuery, which has a helper method to fetch all docs of a specific type.
umbraco.library:GetXmlNodeByXPath($docType) returns a node set (even though there will only be one node in the set), so using the /@id construct is a no-go.
Get url by Document Type
hi everybody! I'm working on the project on Umbraco and on some pages i have static links (i.e. footer links) to the differnet pages.
I want to know is there any opportunity to get url of the page by it's doctype right in template?
now i'm using macro but it's so dirty. I had to create macro for every DocType
<xsl:param name="currentPage"/>
<xsl:variable name="xpathQuery">
<xsl:text>//PrivacyPolicyPage</xsl:text>
</xsl:variable>
<xsl:template match="/">
<xsl:value-of select="umbraco.library:NiceUrl(umbraco.library:GetXmlNodeByXPath($xpathQuery)/@id)" />
</xsl:template>
and i don't want to use any static id parameter for the link, cause it can be changed when user delete and create page. is that possible?
Yarm,
Why not pass in the doc type as a parameter of the macro, so you can reuse the macro for all doc types? Or, as you're wanting to use it from a template, take a look at uQuery, which has a helper method to fetch all docs of a specific type.
Cheers,
/Dirk
Hi Dirk, thank you for prompt answer!
I tried to send docType name as a parameter to macro like this
<xsl:variable name="docType" select="/macro/docType"/>
<xsl:template match="/">
<xsl:value-of select="umbraco.library:NiceUrl(umbraco.library:GetXmlNodeByXPath($docType)/@id)" />
</xsl:template>
but got an error: System.Xml.XPath.XPathException: Expression must evaluate to a node-set.
i've checked - macro gets parameter value, but maybe i shoud convert value to the node-set type...i don't know how
Yarm,
umbraco.library:GetXmlNodeByXPath($docType) returns a node set (even though there will only be one node in the set), so using the /@id construct is a no-go.
How about:
<xsl:variable name="docType" select="/macro/docType"/>
<xsl:template match="/">
<xsl:for-each select="umbraco.library:GetXmlNodeByXPath($docType)/* [@isDoc]">
<xsl:value-of select="umbraco.library.NiceUrl(./@id)" />
</xsl:for-each>
</xsl:template>
If you only need the first doc, then include an addition <xsl:if test="position() = 1">
Cheers,
/Dirk
DIrk, i've just tried your macro and got the same error message
System.Xml.XPath.XPathException: Expression must evaluate to a node-set.
but when i change this line
<xsl:variable name="docType" select="/macro/docType"/>
to
everything is ok. But i can't still create universal macro.
does anybody know how to use umbraco.library:GetXmlNodeByXPath with macro parameter?
ok, i got it, it works, but to save it i have to check checkbox "Skip testing (ignore errors)"
<xsl:variable name="type">
<xsl:text>//</xsl:text>
<xsl:value-of select="/macro/doctype" />
</xsl:variable>
<xsl:template match="/">
<xsl:for-each select="umbraco.library:GetXmlNodeByXPath($type)/node()[1]" >
<xsl:value-of select="umbraco.library:NiceUrl(../@id)" />
</xsl:for-each>
</xsl:template>
is working on a reply...