Copied to clipboard

Flag this post as spam?

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


  • Jon Behrens 53 posts 77 karma points
    May 06, 2011 @ 19:29
    Jon Behrens
    0

    How to get media node from name

    I have a clean 4.5.2 install using .net 3.5. In the media section I have a folder named 'Site' with one image named 'Logo'. On the master page, I would like to do the following:

    <

     

    umbraco:Macro Alias='siteImage' theImage='Site/Logo' runat='server' />

    The macro siteImage then does the following:

    <

     

    xsl:template match="/">

    <

     

    xsl:variable name="theImage" select="/macro/theImage"/>

    <

     

    xsl:variable name="media" select="umbraco.library:GetMedia($theImage, 0)" />

    <

     

    img src='{$media}' />

    </

     

    xsl:template> 

    The problem with this, of course, is that GetMedia takes a node id rather than a node name. So my question is how do I get the node id given that I have the node name? 

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    May 07, 2011 @ 00:04
    Jan Skovgaard
    1

    Hi Jon

    Is there any reason why you don't use the mediaCurrent type as a parameter for your macro? Then you get the id, which you can submit to the GetMedia extension.

    Hope this helps.

    /Jan

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 8x admin c-trib
    May 07, 2011 @ 00:47
    Chriztian Steinmeier
    0

    Hi Jon (+Jan)

    I was about to ask the same :-)

    Using mediaCurrent macro parameter actually goes even further and pre-fetches the XML for the media item, so you don't even need to call GetMedia() - you could do this instead:

    <xsl:template match="/">
        <xsl:variable name="theImage" select="/macro/theImage" />
    
        <img src="{theImage/umbracoFile}" width="{theImage/umbracoWidth}" height="{theImage/umbracoHeight}" alt="{theImage/@nodeName}" />
    
    </xsl:template>

    /Chriztian

  • Jon Behrens 53 posts 77 karma points
    May 07, 2011 @ 01:10
    Jon Behrens
    0

    Thank you both for the reply. I tried that and didn't get anything. That's why I sent it in as text, then at least I had the name of the image. What I couldn't figure out is how to link the image name to the media file in the tree.

    In essence what I am trying to do is have a site-wide logo appear without having to reference it in each page. So there is no page that has a data element referring to the image, it's just in the master masterpage.

    Also - this is a newbe question - how do you get your code to show up compactly? As you can see, mine spreads all over the page. I'm using the code paragraph type.

Please Sign in or register to post replies

Write your reply to:

Draft