Copied to clipboard

Flag this post as spam?

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


  • John Teglmand 8 posts 29 karma points
    Jun 13, 2011 @ 22:19
    John Teglmand
    0

    Get a media files from any place in the doc tree?

    Hi

    I want a macro like this:

    <umbraco:Macro propertyAlias="ImageTop" Alias="ShowImage" runat="server"></umbraco:Macro>

    The macro must seek "media" files through and get the url to show the file white the alias "ImageTop".

    I am on a Umbraco v 4.7

    This is working, but just at top level of the doc tree:

    i know this is the error: select="$currentPage/* [name()=$propertyAlias]"/>

    <xsl:template match="/">

    <xsl:variable name="propertyAlias" select="/macro/propertyAlias"/>
    <xsl:variable name="propertyValue" select="$currentPage/* [name()=$propertyAlias]"/>
            <xsl:if test="$propertyValue!=''">
                <xsl:variable name="mediaItem" select="umbraco.library:GetMedia($propertyValue, 'false')"/>
                <xsl:if test="$mediaItem!=''">
                    <img>
                        <xsl:attribute name="src">
                            <xsl:value-of select="$mediaItem/umbracoFile" />
                        </xsl:attribute>
                        <xsl:attribute name="alt">
                            <xsl:value-of select="$mediaItem/@nodeName" />
                        </xsl:attribute>
                    </img>
                </xsl:if>
            </xsl:if>

    </xsl:template>

  • Kim Andersen 1447 posts 2196 karma points MVP
    Jun 13, 2011 @ 22:33
    Kim Andersen
    0

    Hi John

    So your media picker is located at the top most node in your content tree?

    If that's the case try chagint his line:

    $currentPage/* [name()=$propertyAlias]"/>

    to this

    $currentPage/ancestor-or-self::*[@level='1']/* [name()=$propertyAlias]"/>

    Does that work for you?

    /Kim A

  • John Teglmand 8 posts 29 karma points
    Jun 13, 2011 @ 22:40
    John Teglmand
    0

    Yes, it works!, and yes I have the media picker at the top - Thanks :-)

    Is it possible to search the media lib, without the "media picker" at the top dockument?

  • Kim Andersen 1447 posts 2196 karma points MVP
    Jun 13, 2011 @ 22:50
    Kim Andersen
    0

    You're welcome John!

    I'm not quite sure I understand what you mean when you say "without the media picker at the top document"? You could, without any problems, have a media picker on all of your nodes if that's what you are asking for. Oyherwise could you try to explain your question a little more :)

    /Kim A

Please Sign in or register to post replies

Write your reply to:

Draft