Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
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
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') != '') { %>
......
<% } %>
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.
Should be something like this:
<umbraco:Item field="newsImage" runat="server" xslt="concat('<img src="', umbraco.library:GetMedia({0},'true')/data[@alias='umbracoFile'], '" />')" xsltDisableEscaping="true" />
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']"/>
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=""
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Test 'field' is empty or null
Hi all,
I'm outputting an image to a page:
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
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') != '') { %>
......
<% } %>
Not pretty, as I am trying to get home, but I did it with jQuery for the mo:
I'll look at your method when I get back from the old smoke on Tuesday.
Thanks Tom.
Should be something like this:
Some extra information about getMedia from the Wiki
Getting the url of a media file
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) :)
is working on a reply...