Copied to clipboard

Flag this post as spam?

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


  • Darryl Godden 145 posts 197 karma points
    May 27, 2010 @ 18:02
    Darryl Godden
    0

    Test 'field' is empty or null

    Hi all,

    I'm outputting an image to a page:

    <img src='<umbraco:Item field="newsImage" runat="server"></umbraco:Item>' />

    If there is no image for the news story, Firefox hides it nicely, Chrome however displays the broken image.

    What's the best way to test if there is an image to display?

    Thanks

  • Tom Fulton 2030 posts 4998 karma points c-trib
    May 27, 2010 @ 18:06
    Tom Fulton
    0

    This thread might have your answer:

    http://our.umbraco.org/forum/developers/api-questions/9454-Parsing-Umbraco-page-fields-within-inline-NET-in-template?p=0

    I've never used inline .NET in a template, but would imagine it's something like this, maybe?

    <% if (umbraco.library:GetItem('newsImage') != '') { %>

    ......

    <% } %>

     

  • Darryl Godden 145 posts 197 karma points
    May 27, 2010 @ 18:15
    Darryl Godden
    0

    Not pretty, as I am trying to get home, but I did it with jQuery for the mo:

    <script type="text/javascript">
            $(document).ready(function () {
                var ni = $("#newsImage").attr("src");
    
                if (ni == "")
                {
                    $("#newsImage").hide();
                }
            });
        </script>

    I'll look at your method when I get back from the old smoke on Tuesday.

    Thanks Tom.

  • Bert 128 posts 251 karma points
    May 27, 2010 @ 18:22
    Bert
    0

    Should be something like this:


    <umbraco:Item field="newsImage" runat="server" xslt="concat('&lt;img src=&quot;', umbraco.library:GetMedia({0},'true')/data[@alias='umbracoFile'], '&quot; /&gt;')" xsltDisableEscaping="true" />

     

  • Bert 128 posts 251 karma points
    May 27, 2010 @ 18:24
    Bert
    0

    Some extra information about getMedia from the Wiki

    Getting the url of a media file

      <xsl:value-of select="umbraco.library:GetMedia(1057, 'false')/data [@alias = 'umbracoFile']"/>
  • Bert 128 posts 251 karma points
    May 27, 2010 @ 19:03
    Bert
    0

    and another post forgot the textIfEmpty property. Should show empty string when the field is not populated. (I discovered the edit function, it's called post over and over again) :)

    textIfEmpty=""
Please Sign in or register to post replies

Write your reply to:

Draft