Copied to clipboard

Flag this post as spam?

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


  • Paul Griffiths 370 posts 1021 karma points
    Jun 29, 2014 @ 13:16
    Paul Griffiths
    0

    Syntax to test whether a media file has been selected

    Hi All,

    I have images located in a folder in my media section and I have the code working so that if a user selects an image via the media picker data type it displays it fine but I want to put an awaiting photo image in place if they decide not to select an image.

    The first if Test is working fine but the second if test wont seem to pull in the awaiting image png that I am storing in an images folder located with the rest of the installation files.

    I think im on the right lines but the sytax is wrong somewhere. can anyone please help me out.

        <xsl:if test="number(driverImage) &gt; 0">
    <xsl:variable name="selectedMedia" select="umbraco.library:GetMedia(driverImage, 0)" />             
    <img src="{$selectedMedia/umbracoFile}?width=106&amp;height=130&amp;mode=crop" alt="{$selectedMedia/@nodeName}" />
    </xsl:if>
    
    <xsl:if test="number(driverImage) &lt; 0">                  
    <img src="/images/awaiting-image.png?width=106&amp;height=130&amp;" alt="{$currentPage/@nodeName}" />                   
    </xsl:if>
    

    Thanks

    Paul

  • Paul Griffiths 370 posts 1021 karma points
    Jun 29, 2014 @ 13:22
    Paul Griffiths
    100

    Hi,

    I found a solution to get around this. After realising that the value was of type string i used the following test

    <xsl:if test="string(driverImage) = ''">                  
    <img src="/images/awaiting-image.png?width=106&amp;height=130&amp;" alt="{$currentPage/@nodeName}" />                   
    </xsl:if>
    

    Seemed to work and is displaying the image so happy days. Perhaps I should think a bit harder next time lol

    Thnaks Paul

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jun 29, 2014 @ 13:26
    Dennis Aaen
    1

    Hi Paul,

    What if you are doing it this way:

    <xsl:if test="driverImage = ''">                  
     <img src="/images/awaiting-image.png?width=106&amp;height=130&amp;"alt="{$currentPage/@nodeName}"/>                  
    </xsl:if>
     

    And try to check if the path is correct for the image. You can check the path in firebug or chrome developer tools, by doing this can get an idea of if it´s the correct path.

    One thing you also could try is just remove the if statement, just to make sure that the path to the image is correct, then you know that the if statement is the problem.

    Hope this helps, 

    /Dennis

  • Paul Griffiths 370 posts 1021 karma points
    Jun 29, 2014 @ 13:34
    Paul Griffiths
    0

    Hi Dennis

    Thanks for your prompt response. Ive managed to solve the issue i was having pretty much how you suggested :)

    I just needed to think a bit harder lol

    Cheers mate

    Paul

Please Sign in or register to post replies

Write your reply to:

Draft