Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Yarm 7 posts 27 karma points
    Jul 21, 2011 @ 13:50
    Yarm
    0

    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?


  • Dirk De Grave 4537 posts 6006 karma points MVP 3x admin c-trib
    Jul 22, 2011 @ 08:12
    Dirk De Grave
    0

    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

  • Yarm 7 posts 27 karma points
    Jul 22, 2011 @ 08:43
    Yarm
    0

    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


  • Dirk De Grave 4537 posts 6006 karma points MVP 3x admin c-trib
    Jul 22, 2011 @ 08:49
    Dirk De Grave
    0

    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

  • Yarm 7 posts 27 karma points
    Jul 22, 2011 @ 09:13
    Yarm
    0

    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

    <xsl:variable name="docType">
      <xsl:text>//TermsAndConditionsPage</xsl:text>
    </xsl:variable
    >

    everything is ok. But i can't still create universal macro.

  • Yarm 7 posts 27 karma points
    Jul 25, 2011 @ 09:39
    Yarm
    0

    does anybody know how to use umbraco.library:GetXmlNodeByXPath with macro parameter?

  • Yarm 7 posts 27 karma points
    Jul 25, 2011 @ 10:20
    Yarm
    0

    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>


  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies