Copied to clipboard

Flag this post as spam?

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


  • Shaun Brown 6 posts 22 karma points
    Jul 23, 2009 @ 14:03
    Shaun Brown
    0

    Trouble with getting media out using unbuilt functions

    Hello again guys/girls,

    Firstly thanks for the information you've given me so far on various other issues i've had.

    However, I'm seeking some more advice on pulling media out of the media library...

    Basically how i've got the system setup is by having a doc type with media picker (with alias of "rightAds"), I then go from the content section, pick the media with the media picker (on its own tab)

    Now... with the media picked I can surely reference it to the template?

    The way I'm doing it (must be wrong as it's not working)

    This is extended from a master page template which possitions it on the right

    [code]

    <asp:content ContentPlaceHolderId="RightAdvertisements" runat="server">
        <umbraco:Item runat="server" field="rightAds" xslt='<xsl:value-of select="umbraco.library:GetMedia(./data [@alias = "rightAds"], "false")"/>' XsltDisableEscaping="true" />
    </asp:content>

    [/code]

    Now, the alias rightAds is from the media picker being passed into it.  I can't figure out how this would pull the media out from the ID being returned?

     

    Any help is muchly appreciated.

     

    Thank you very much in advance,

    Shaun

  • dandrayne 1138 posts 2262 karma points
    Jul 23, 2009 @ 14:06
    dandrayne
    1

    I prefer straight xslt instead of inline, so here's a solution for that

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxml="urn:schemas-microsoft-com:xslt"
    xmlns:umbraco.library="urn:umbraco.library"
    exclude-result-prefixes="msxml umbraco.library">


    <xsl:output method="xml" omit-xml-declaration="yes"/>

    <xsl:param name="currentPage"/>

    <xsl:template match="/">



    <xsl:if test="$currentPage/data [@alias='rightAds'] != ''">
    <img alt="">
    <xsl:attribute name="src">
    <xsl:value-of select="umbraco.library:GetMedia($currentPage/data [@alias='rightAds'], 'false')/data [@alias = 'umbracoFile']" />
    </xsl:attribute>
    </img>
    </xsl:if>

    </xsl:template>

    </xsl:stylesheet>

    I think the trick here is that GetMedia returns the media item node, not just the path to the file (thats /data [@alias='umbracoFile']

    umbraco.library:GetMedia($currentPage/data [@alias='rightAds'], 'false')/data [@alias = 'umbracoFile']

     

    Dan

  • Shaun Brown 6 posts 22 karma points
    Jul 23, 2009 @ 14:12
    Shaun Brown
    0

    Hello Dan, how would I then refference this for the <umbraco:Item>  And of course where would I put this big chunk of XSLT code?

    And, How would this then interact/link with the <umbraco:Item attribute?

     

    I ideally need to know this for future refference, and so I know why and how it works.

     

    Thank you very much for your input Dan.

    Shaun

  • Peter Dijksterhuis 1442 posts 1722 karma points
    Jul 23, 2009 @ 14:36
    Peter Dijksterhuis
    2

    Shaun,

    to use the xslt Dan described, you need to create a macro. Go to the developer-section and right-click XSLT and Create a new one. (Just choose clean-file and have 'create macro checked')

    Then, overwrite the xslt with the xslt that Dan wrote.

    In your template, instead of umbraco:Item, you must insert a macro. (There's a button at the top where you can automatically insert a macro).

    Does this help you further?

    Peter

  • Shaun Brown 6 posts 22 karma points
    Jul 23, 2009 @ 14:48
    Shaun Brown
    0

    Thank you Peter, this has helped me solve the issue.

  • dandrayne 1138 posts 2262 karma points
    Jul 23, 2009 @ 15:50
    dandrayne
    0

    thanks for the elaboration peter, and good luck shaun.

  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    Jul 23, 2009 @ 18:33
    Morten Bock
    0

    Just to go sith the other solution, you could also use the inline xslt:

    http://umbraco.org/documentation/books/inline-xslt

    <umbraco:Item runat="server" field="rightAds" xslt="concat('&lt;img src=&quot;', umbraco.library:GetMedia({0},'true')/data[@alias='umbracoFile'], '&quot; /&gt;')" xsltDisableEscaping="true" />
Please Sign in or register to post replies

Write your reply to:

Draft