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.
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?
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 <= $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 <= $maxLevel]) > 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!
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!!
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.
Hi Chuck,
It is worth checking what the value of "data[@alias='linkedFile']" is ... just in case it isn't a number.
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.
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?
You should be able to get that using GetMedia then:
Note: what you use in your if-statement should be the same as in the GetMedia-part.
HTH,
Peter
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:
I realize there may be a more efficient method to do this, but I'm 1 month into this umbraco thing!! Thanks!
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!!
Hi Chuck
Is it possible to see a page, where your code is in action?
/Jan
I was a bit slow with my reply there. Glad you got it all sorted out :)
/Jan
is working on a reply...