Copied to clipboard

Flag this post as spam?

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


  • Stevie B. Gibson 70 posts 30 karma points
    Sep 06, 2012 @ 11:01
    Stevie B. Gibson
    0

    Get media by alias in xslt and template

    Hi, I'm building a set of template/xslt where I would like to display general images (like logos, layout images etc.) took from media in order to give the user the chance tu change them without manually put the file on the webserver.

    I've two problems:

    - I'm not able to take the media using alias. I used this command and it works src="{umbraco.library:GetMedia(1096, false())/data[@alias='umbracoFile']}" but i would like to use something like src="{umbraco.library:GetMedia('logo', false())/data[@alias='umbracoFile']}".

    - I'm not able to do the same thing in templates. I've to create a macro that return the correct path or I can do something inline?

    Thanks in advance.

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 8x admin c-trib
    Sep 06, 2012 @ 11:13
    Chriztian Steinmeier
    1

    Hi Stevie,

    You should be able to grab by alias using the data[@alias] syntax:

    <xsl:variable name="mediaID" select="$currentPage/data[@alias = 'logo']" />
    
    <xsl:if test="$mediaID">
        <xsl:variable name="mediaNode" select="umbraco.library:GetMedia($mediaID, false())" />
        <img src="{$mediaNode/data[@alias = 'umbracoFile']}" alt="{$mediaNode/@nodeName}" />
    </xsl:if>

    Please note that data[@alias] is from "the old (or legacy) XML schema" (search for it). After Umbraco 4.5 (I think) we got a much improved and simpler XML schema to work with...

    /Chriztian

  • Fuji Kusaka 2203 posts 4220 karma points
    Sep 06, 2012 @ 11:21
    Fuji Kusaka
    0

    Hi Stevie,

    In your xslt add a variable something like "mediaPicker"

    <xsl:variable name="mediaPicker" select="$currentPage/logo"/> 

    and make a test to see it ever a file is choose from the media section

    <xsl:value-of select="umbraco.library:GetMedia(@id, 0)/umbracoFile"/> 
  • Fuji Kusaka 2203 posts 4220 karma points
    Sep 06, 2012 @ 11:23
    Fuji Kusaka
    0

    Sorry just noticed Chriztian's reply now while replying.

  • Stevie B. Gibson 70 posts 30 karma points
    Sep 06, 2012 @ 11:26
    Stevie B. Gibson
    0

    I don't want the user to specify the logo in every page. I would like to get the file from the media library that has the alias 'logo', not the one choosed in the logo param of the page.

    @Chriztian: I used the legacy schema to recycle old xslts, I would like to upgrade them in a second time.

     

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 8x admin c-trib
    Sep 06, 2012 @ 11:38
    Chriztian Steinmeier
    0

    Aha - different problem, I see...

    Well, then you need to grab the containing folder first - something like this:

    <!-- Grab the media folder -->
    <xsl:variable name="folder" select="umbraco.library:GetMedia(FOLDER_ID, true())" />
    
    <!-- Process the logo image  -->
    <xsl:apply-templates select="$folder/node[@nodeTypeAlias = 'logo']" />
    
    <!-- Template for media file -->
    <xsl:template match="node[@nodeTypeAlias = 'logo']">
        <img src="{data[@alias = 'umbracoFile']}" alt="{@nodeName}" />
    </xsl:template>

    Downside is you have to get all media if you cannot confine the images to a specific folder...

    /Chriztian

Please Sign in or register to post replies

Write your reply to:

Draft