Copied to clipboard

Flag this post as spam?

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


  • Mads Sørensen 188 posts 433 karma points
    May 30, 2012 @ 09:27
    Mads Sørensen
    0

    Display images with Xlst and MediaPicker in umbraco 4.7.2

    Hey Guys

    I've searched all morning to find a simple solution to display images with xslt and the media picker.

    This is what figured out for now, BUT, no images are displayed :'(

    It's bit confusing for a rookie XSLT dude like me :P

    <div id="fokusMasterObject">
        <a href="#">
        <xsl:variable name="imageId" select="$currentPage/data[@alias = 'fokusFromMainWebsite']" />
        <xsl:if test="$imageId != ''">
            <xsl:variable name="image" select="umbraco.library:GetMedia($imageId, true)" />
            <img src="{$image/data[@alias = 'umbracoFile']}" width="{$image/data[@alias = 'umbracoWidth']}" height="{$image/data[@alias = 'umbracoHeight']}" />
        </xsl:if>
        </a>
    </div>

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    May 30, 2012 @ 09:37
    Chriztian Steinmeier
    0

    Hi Mads,

    You're just unfortunate to have found some XSLT for the "Legacy XML Schema" (search for it, to see what changed).

    To do the same with the New XML Schema (since, I believe, Umbraco 4.5):

    <div id="fokusMasterObject">
        <a href="#">
            <xsl:variable name="imageId" select="$currentPage/fokusFromMainWebsite" />
            <xsl:if test="normalize-space($imageId)">
                <xsl:variable name="image" select="umbraco.library:GetMedia($imageId, false())" />
                <img src="{$image/umbracoFile}" width="{$image/umbracoWidth}" height="{$image/umbracoHeight}" />
            </xsl:if>
        </a>
    </div>

    /Chriztian 

  • Mads Sørensen 188 posts 433 karma points
    May 30, 2012 @ 09:51
    Mads Sørensen
    0

    Hey Steinmeier
    As usual you are getting things working for me :o)

    I guess this is what you where talking about whit the new schema http://our.umbraco.org/wiki/reference/xslt/45-xml-schema/xslt-examples-updated-to-new-schema

  • Mads Sørensen 188 posts 433 karma points
    May 30, 2012 @ 10:37
    Mads Sørensen
    0

    Hey Christian

    Your suggestion worked fine but when i kombine it with this:

    <div id="fokusMasterObject">  
             <xsl:if test="normalize-space(fokusFromMainWebsiteLink)">
             <a href="{umbraco.library:NiceUrl(fokusFromMainWebsiteLink}">
            
                    <xsl:variable name="imageId" select="$currentPage/fokusFromMainWebsite" />
                    <xsl:if test="normalize-space($imageId)">
                            <xsl:variable name="image" select="umbraco.library:GetMedia($imageId, false())" />
                    <img src="{$image/umbracoFile}" width="{$image/umbracoWidth}" height="{$image/umbracoHeight}" />
                    </xsl:if>
            </a>
            </xsl:if>  
       
    </div>

    Error occured!

    I gues it maybe is because i use <xsl:if></xsl:if> inside in a <xsl:if></xsl:if> ????

    <xsl:if>
    <xsl:if></xsl:if>
    </xsl:if>
  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    May 30, 2012 @ 10:54
    Chriztian Steinmeier
    0

    Hi Mads,

     

    You can have as many nested xsl:if statements as you can fit in a big barrel (figuratively speaking - you know what I mean :-).

    I can think of two things that would go wrong:

    - You're missing the closing parenthesis in the call to NiceUrl() - If that's just a typo here, the other thing would be that fokusFromMainWebsiteLink needs to be a page id - is that the case? 

    /Chriztian

  • Mads Sørensen 188 posts 433 karma points
    May 30, 2012 @ 11:04
    Mads Sørensen
    0

    just figured it out myself :o)

    Embarrassing :o)

     

    <div id="fokusMasterObject">
            
             <xsl:if test="normalize-space($currentPage/fokusFromMainWebsiteLink)">
             <a href="{umbraco.library:NiceUrl($currentPage/fokusFromMainWebsiteLink)}">
            
                    <xsl:variable name="imageId" select="$currentPage/fokusFromMainWebsite" />
                    <xsl:if test="normalize-space($imageId)">
                            <xsl:variable name="image" select="umbraco.library:GetMedia($imageId, false())" />
                    <img src="{$image/umbracoFile}" width="{$image/umbracoWidth}" height="{$image/umbracoHeight}" />
                    </xsl:if>
            </a>
            </xsl:if>  
       
    </div>
Please Sign in or register to post replies

Write your reply to:

Draft