Copied to clipboard

Flag this post as spam?

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


  • Connie DeCinko 931 posts 1160 karma points
    Jul 26, 2010 @ 20:21
    Connie DeCinko
    0

    Display Content Picker link in master template

    In my master template, I want to have a hyperlink that a user can edit via Umbraco.  I added a property to my master document type of Content Picker.  I've tried many ways to add the content picker link to my master template including XSLT and I either get blank results or errors.

    How do I code this while also ensuring that all pages that inherit from my master document type display the link?

     

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Jul 26, 2010 @ 20:41
    Tom Fulton
    0

    Something like this should work, in an XSLT macro:

    <xsl:if test="string($currentPage/data [@alias='myLinkProperty']) != ''">
    <a>
    <xsl:attribute name="href"><xsl:value-of select="umbraco.library:NiceUrl($currentPage/data [@alias='myLinkProperty'])"/></xsl:attribute>
    Click Me
    </a>
    </xsl:if>

    Or if you're using 4.5, it would be $currentPage/myLinkProperty instead

  • Connie DeCinko 931 posts 1160 karma points
    Jul 26, 2010 @ 20:51
    Connie DeCinko
    0

    I am using 4.5 and was using the old format.  Using $currentPage/myLinkProperty and it seems to work fine.  Now, I cannot get the node name.  Using <xsl:value-of select="@nodeName"/> in place of Click Me causes nothing to display.

     

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Jul 26, 2010 @ 21:04
    Tom Fulton
    0

    Try <xsl:value-of select="$currentPage/@nodeName"/>  :)

  • Connie DeCinko 931 posts 1160 karma points
    Jul 26, 2010 @ 21:09
    Connie DeCinko
    0

    That give me the node name of the current page instead of the node name of the targeted page.

     

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Jul 26, 2010 @ 21:12
    Tom Fulton
    0

    Oh, sorry, wasn't thinking.  To get properties from the targeted page you can use GetXmlNodeById:

    <xsl:value-of select="umbraco.library:GetXmlNodeById($currentPage/myLinkProperty)/@nodeName"/>

     

  • Connie DeCinko 931 posts 1160 karma points
    Jul 26, 2010 @ 21:16
    Connie DeCinko
    0

    Awesome, another step closer.  Now, all I need is to make it recursive so every page based upon that document type defaults to the value set in the master doc type.

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Jul 26, 2010 @ 21:24
    Tom Fulton
    0

    This *should* get the value recursively:

    <xsl:value-of select="$currentPage/ancestor-or-self::* [@isDoc and myLinkProperty != '']/myLinkProperty"/>


    Make sure to update this Xpath statement in your IF, href attribute and inside the NiceUrl function

  • Connie DeCinko 931 posts 1160 karma points
    Jul 26, 2010 @ 23:10
    Connie DeCinko
    0

    Ok, I think I have my final solution so I thought I would share.  I ran into another issue... I wanted the property from the currentPage to take priority. I only wanted to go the the ancestor property if the currentPage property is empty.  With ancestor-or-self you cannot control that.  So I check for currentPage first.

     

     <xsl:choose>
      <xsl:when test="string($currentPage/hotLink) != ''">
       <a>
        <xsl:attribute name="href">
         <xsl:value-of select="umbraco.library:NiceUrl($currentPage/hotLink)"/>
        </xsl:attribute>
        <xsl:value-of select="umbraco.library:GetXmlNodeById($currentPage/hotLink)/@nodeName"/>
       </a>
      </xsl:when>
      <xsl:when test="string($currentPage/ancestor::* [@isDoc and hotLink!= '']/hotLink) != ''">
       <a>
        <xsl:attribute name="href">
         <xsl:value-of select="umbraco.library:NiceUrl($currentPage/ancestor::* [@isDoc and hotLink!= '']/hotLink)"/>
        </xsl:attribute>
        <xsl:value-of select="umbraco.library:GetXmlNodeById($currentPage/ancestor::* [@isDoc and hotLink!= '']/hotLink)/@nodeName"/>
       </a>
      </xsl:when>
      <xsl:otherwise>

      </xsl:otherwise>
     </xsl:choose>
  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Jul 27, 2010 @ 00:03
    Matt Brailsford
    0

    Hi Connie

    Why not just use a recursive macro property?

    Just define a property on your macro, then set it's value when you embed it like so

     

    Umbraco will automaticaly check the current page, then it's ancestors untill it finds a value, and then pass it into your macro.

    Matt

    UPDATE (The example got stripped from my phone)

    <umbraco:macro alias="mymacroalias" mypropertyalais="[$mydocpropertyalias]" runat="server" />
  • Tom Fulton 2030 posts 4998 karma points c-trib
    Jul 27, 2010 @ 01:39
    Tom Fulton
    0

    Ah, forgot all about that. 

    If you prefer your existing solution I think you can get the recursion behaving like you want by adding position() = 1 to the Xpath conditions, according to this post anyway

    Matt's solution may be easier though :)

    -Tom

  • Connie DeCinko 931 posts 1160 karma points
    Jul 29, 2010 @ 18:37
    Connie DeCinko
    0

    Matt,

    Ok, so if I understand, the idea is to pass a property from the page to the macro and then use that value in my macro?  I sort of get it...

     

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Jul 29, 2010 @ 18:47
    Matt Brailsford
    0

    Hi Connie,

    Thats correct yes. Define the property on your doc type(s), then in your template, pass the value to your macro like so

    <umbraco:macro alias="mymacroalias" mypropertyalais="[$mydocpropertyalias]" runat="server" />

    Then you can retreive the value from within the macro like so

    <xsl:variable name="myprop" select="/macro/mypropertyalias"/>

    (Notice the /macro/ at the begining. I'm not sure if this has changed in 4.5 thought)

    Matt

  • Connie DeCinko 931 posts 1160 karma points
    Jul 29, 2010 @ 18:57
    Connie DeCinko
    0

    Yes!  Now I know how to pass in values to a macro, which will be helpful for some other tasks.  Below is my final XSLT code which is much simpler and cleaner than what I had before.  One thing, why do I always have to check for an empty value?  Does that just satisfy the editor?

    <xsl:variable name="theHotLink" select="/macro/hotLink"/>

    <xsl:template match="/">

      <xsl:if test="string($theHotLink) != ''">
        <a>
          <xsl:attribute name="href">
            <xsl:value-of select="umbraco.library:NiceUrl($theHotLink)"/>
          </xsl:attribute>
          <xsl:value-of select="umbraco.library:GetXmlNodeById($theHotLink)/@nodeName"/>
        </a>
      </xsl:if>
  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Jul 29, 2010 @ 19:19
    Matt Brailsford
    0

    Hi Connie,

    Checking the string length is good practise, and prevents the value from being used if it is empty, which could cause an XSLT template error otherwise.

    Matt

  • techUsr 8 posts 28 karma points
    Aug 09, 2010 @ 07:52
    techUsr
    0

    Hi,

    I have created a Master template which displays a text string and related links using XSLT/Macro(Using Umbraco 4.5).When I try to access it from my child page,it displays the textstring but does not display anything for relatedlinks.Can anyone help me with this?

    Thanks,

    Brady

     

Please Sign in or register to post replies

Write your reply to:

Draft