Copied to clipboard

Flag this post as spam?

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


  • Maciej Drahusz 12 posts 33 karma points
    Jun 27, 2013 @ 10:17
    Maciej Drahusz
    0

    Choosing photo instance

    Hi

    I'm struggling with this supposingly trivial condition. I would like umbraco to check if there is a Banner Image if not to use the standard instance. I'm using following choose condition.

    <xsl:variable name = "imagePath" select="umbraco.library:GetMedia($articleImage, 0)/umbracoFile" />  <xsl:variable name = "articleBanner" select="concat(substring-before($imagePath, '.'), '_banner.jpg')" />

    <xsl:choose>
    <xsl:when test="$articleBanner != ''">
    <img src="{$articleBanner}"/>
    </xsl:when>
    <xsl:otherwise>
    <img src="/media/1058/noimage.jpg"/>
    </xsl:otherwise>
    </xsl:choose>

    Any Ideas?

    Thanks
    Maciej

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    Jun 27, 2013 @ 10:28
    Chriztian Steinmeier
    0

    Hi Maciej,

    Do you want to check for the physical image on disk (e.g.: "filename_banner.jpg") or just make sure that $articleImage has an image selected?

    /Chriztian

  • Maciej Drahusz 12 posts 33 karma points
    Jun 27, 2013 @ 10:32
    Maciej Drahusz
    0

    Hi Chriztian

    I'm checking if there is photo on the disk. Basically I'm using image cropper to produce _banner photo and then checking if it was produced that instance should be used otherwise it will do something else.

    Regards
    Maciej 

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jun 27, 2013 @ 10:34
    Dennis Aaen
    0

    Hi Maciej,

    Will try to help you. I can´t see what you are using the _banner.jpg but probably just me,

    Have you try someting like this:

    <xsl:variable name="articleImage" select="umbraco.library:GetMedia($currentPage/yourMediaPickerAlias, 0)/umbracoFile" />  
    <xsl:choose>
        <xsl:when test="$articleImage!= ''">
         <img src="{$articleImage}"/>
       </xsl:when>
      <xsl:otherwise>
        <img src="/media/1058/noimage.jpg"/>
    </xsl:otherwise>
    </xsl:choose>

    With the code above you should be able to dispaly the image from the page that you are on, if one is selected in a mediaPicker. Or is just take the no image. I hope this will work for you.

    /Dennis

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    Jun 27, 2013 @ 10:37
    Chriztian Steinmeier
    1

    Okay - if you're using the Image Cropper, you will have the crops in the XML - so you could do something like this:

    <img src="/media/1058/noimage.jpg">
        <!-- If the $articleImage has content -->
        <xsl:if test="normalize-space($articleImage)">
            <!-- Grab the media node -->
            <xsl:variable name="mediaNode" select="umbraco.library:GetMedia($articleImage, 0)" />
            <!-- Select the banner crop (if present) -->
            <xsl:variable name="bannerCrop" select="$mediaNode//crop[@name = 'banner']" />
            <xsl:if test="$bannerCrop">
                <!-- Override the img tag src attribute -->
                <xsl:attribute name="src"><xsl:value-of select="$bannerCrop/@url" /></xsl:attribute>
            </xsl:if>
        </xsl:if>
    </img>

    /Chriztian

  • Maciej Drahusz 12 posts 33 karma points
    Jun 27, 2013 @ 10:43
    Maciej Drahusz
    0

    Thanks Dennis

    It displays the image but doesn't make the second condition fire. It shows when the banner photo is there but if there isn't one it doesnt show noimage.jpg.

    /Maciej

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jun 27, 2013 @ 10:49
    Dennis Aaen
    0

    Okay Maciej,

    I think that you should try what Chrizitan suggests in his post. He is super good at XSLT.

    Many of us in this forum, also know him as Mr. XSLT :)

    /Dennis 

  • Maciej Drahusz 12 posts 33 karma points
    Jun 27, 2013 @ 10:57
    Maciej Drahusz
    0

    Thanks Chriztian

    That's spot on. You trully live up to the expectations.

    I will include you in my tonight's pray. :)

    Many Thanks
    Maciej 

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    Jun 27, 2013 @ 11:00
    Chriztian Steinmeier
    0

    Wow - thanks to both of you — very kind :-)

    /Chriztian

  • Maciej Drahusz 12 posts 33 karma points
    Jun 27, 2013 @ 13:47
    Maciej Drahusz
    0

    I almost thought I'm finished. Is Chriztian's code choosing between noimage if there is no banner image and _banner if there is one? Currently it picks banner if there is one but shows nothing if isn't.  

    /Maciej

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    Jun 27, 2013 @ 13:53
    Chriztian Steinmeier
    0

    Hi Maciej,

    Technically, it writes the "noimage" as the default image (obviously /media/1058/noimage.jpg must exist) - then, if the $articleImage variable has content, it will find that media item, and if it has a "banner" crop, it will rewrite the img tag's src attribute to use the crop instead.

    Can you maybe show how you're using it - maybe you forgot to include something?

    /Chriztian

  • Maciej Drahusz 12 posts 33 karma points
    Jun 27, 2013 @ 14:01
    Maciej Drahusz
    0

    Actually now it worked. It looks like it works in some instances but not in other. I must look around and see what's the difference between them. It might be come cashing issue or I didn't generate crops in some situations. Thanks for your help again. 

    /Maciej

Please Sign in or register to post replies

Write your reply to:

Draft