Copied to clipboard

Flag this post as spam?

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


  • Chuck Johnson 4 posts 24 karma points
    Feb 06, 2010 @ 20:02
    Chuck Johnson
    0

    XSLT Dynamic Menu Item To Media File Direct Link Problem

    I am trying to make the menu xslt set the href for a menu item link directly to a file loaded in the media section if the media picker has a file selected. My  when/otherwise is working because i can hardcode a value in the href and it will link. I can't seem to dynamically identify and return the actual path to the media file.

    <xsl:when test="string(./data [@alias = 'linkedFile']) != ''">
            <a href="{umbraco.library:GetMedia(current()/data[@alias='linkedFile'], 'false')/data[@alias='umbracoFile']}">
             <xsl:value-of select="@nodeName"/>
            </a>
    </xsl:when>

    The media item node id is 1086.

    Any help would be appreciated.

  • Lee Kelleher 3945 posts 15163 karma points MVP 10x admin c-trib
    Feb 06, 2010 @ 20:39
    Lee Kelleher
    0

    Hi Chuck,

    It is worth checking what the value of "data[@alias='linkedFile']" is ... just in case it isn't a number.

    <xsl:value-of select="data[@alias='linkedFile']" />

    Other than that, I wrote a blog post a while ago about how to safely handle the GetMedia function call.

    http://blog.leekelleher.com/2009/11/30/how-to-use-umbraco-library-getmedia-in-xslt/

    Good luck, Lee.

  • Chuck Johnson 4 posts 24 karma points
    Feb 06, 2010 @ 23:44
    Chuck Johnson
    0

    when i place the code in that you've shown above, the menu displays 1086, which it should i suppose. Thanks Lee. This helps me validate the media node id.

    So now the question is, how do I get the href to contain the path to the actual file?

  • Peter Dijksterhuis 1442 posts 1722 karma points
    Feb 07, 2010 @ 00:11
    Peter Dijksterhuis
    1

    You should be able to get that using GetMedia then:

    <a href="{umbraco.library:GetMedia(data[@alias='linkedFile'], 'false')/data[@alias='umbracoFile']}">

    Note: what you use in your if-statement should be the same as in the GetMedia-part.

    HTH,

    Peter

     

  • Chuck Johnson 4 posts 24 karma points
    Feb 07, 2010 @ 00:41
    Chuck Johnson
    0

    I copied your code in Peter and I end up with the same thing i was getting before, nothing :( Here is the code I am using:

      <xsl:for-each select="$parent/node [string(./data [@alias='umbracoNaviHide']) != '1' and @level &lt;= $maxLevel]"> 
       <li> 
        <xsl:choose>
         <!-- test to see if customer wants menu item to link offsite -->
         <xsl:when test="string(./data [@alias = 'offsiteURL']) != ''">
          <!-- if so create offsite link -->
          <a href="{./data [@alias = 'offsiteURL']}">
           <xsl:value-of select="@nodeName"/>
          </a>
         </xsl:when>
         <xsl:otherwise>
          <xsl:choose>
           <!-- test to see if customer wants menu item to link directly to media item -->
           <xsl:when test="string(./data [@alias = 'linkedFile']) != ''">
            <!-- if so create direct link to media item -- this doesn't work, returns nothing -->
            <a href="{umbraco.library:GetMedia(data[@alias='linkedFile'], 'false')/data[@alias='umbracoFile']}">
              <!-- a tag shows node 1086 which is the file, the url just isn't populated with a path -->
       <xsl:value-of select="data[@alias='linkedFile']"/>
            </a>
           </xsl:when>
           <xsl:otherwise>
            <!-- ur here because no offsite or direct media item link was selected -->
            <a href="{umbraco.library:NiceUrl(@id)}">
              <xsl:if test="$currentPage/ancestor-or-self::node/@id = current()/@id">
               <!-- we're under the item - you can do your own styling here -->
               <xsl:attribute name="class">current</xsl:attribute>
              </xsl:if>
              <xsl:value-of select="@nodeName"/>
            </a>
           </xsl:otherwise>
          </xsl:choose>
         </xsl:otherwise>
        </xsl:choose>
          <xsl:if test="count(./node [string(./data [@alias='umbracoNaviHide']) != '1' and @level &lt;= $maxLevel]) &gt; 0">  
         <ul>
          <xsl:call-template name="drawNodes">   
           <xsl:with-param name="parent" select="."/>   
          </xsl:call-template> 
         </ul>
        </xsl:if>
        </li>
      </xsl:for-each> 

    I realize there may be a more efficient method to do this, but I'm 1 month into this umbraco thing!! Thanks!

  • Chuck Johnson 4 posts 24 karma points
    Feb 07, 2010 @ 00:54
    Chuck Johnson
    0

    I solved it. The code above does work. I have a image i am successfully displaying on the main page so i selected it instead of the one i'd been trying and it worked. I selected the image above for the main page and it didn't. There must be something wrong with that file in the media folder. Man that took a long time to figure out. Thanks Guys!!

  • Jan Skovgaard 11258 posts 23500 karma points MVP 7x admin c-trib
    Feb 07, 2010 @ 00:54
    Jan Skovgaard
    0

    Hi Chuck

    Is it possible to see a page, where your code is in action?

    /Jan

  • Jan Skovgaard 11258 posts 23500 karma points MVP 7x admin c-trib
    Feb 07, 2010 @ 00:55
    Jan Skovgaard
    0

    I was a bit slow with my reply there. Glad you got it all sorted out :)

    /Jan

  • 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