Copied to clipboard

Flag this post as spam?

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


  • Garrett Fisher 341 posts 496 karma points
    Sep 22, 2009 @ 17:33
    Garrett Fisher
    0

    Null Check on <umbraco:Item> tag?

    Hi,

    I need to do something equivalent to a null check in a template, for example only write an image to a page if there IS an image associated with it.  How is this done in Umbraco?  My code is below:


    <img src="<umbraco:Item field='articlePhoto' runat='server'></umbraco:Item>" style="width:260px;float:left; padding:12px 10px 10px 0px;" />

     

    Thanks,

    Garrett

  • dandrayne 1138 posts 2262 karma points
    Sep 22, 2009 @ 17:39
    dandrayne
    0

    You can either

    1. Insert the <img src=" and style="whatever:bleh" /> before and after the field when inserting the field in the template - heres an example from my own project
      <umbraco:Item field="pageSideBarTitle" insertTextBefore="&lt;h2&gt;" insertTextAfter="&lt;/h2&gt;" runat="server"></umbraco:Item> 
    2. use xslt and wrap
      <xsl:if test="string($currentPage/data [@alias='articlePhoto') != ''"> </xsl:if> around the call to the image

    Using both ways, the image tag will only be written if the field isnt empty

    Dan ;-)

  • dandrayne 1138 posts 2262 karma points
    Sep 22, 2009 @ 17:40
    dandrayne
    1

    Should note that the "insertTextBefore" etc needs to be escaped, but if you do it via the "insert page field" dialogue box this is done automatically.

Please Sign in or register to post replies

Write your reply to:

Draft