Copied to clipboard

Flag this post as spam?

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


  • TomLeads 20 posts 42 karma points
    Feb 01, 2011 @ 14:33
    TomLeads
    0

    if statement in masterpage

    Hi, hope this is in the right place.

    I need to create something like this:

    <li><a href="#"><img src="photo.jpg" /></a></li>

    The photo is a document/property type. But it might not exist. If it doesn't exist I don't want to render the <li>

    Is there a simple if statement to check for a null value or something like that?

    Thanks

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Feb 01, 2011 @ 14:51
    Jan Skovgaard
    1

    Hi Tom

    Any particular reason why you want to make this directly in the masterpage?

    I suggest looking into making a XSLT macro to render your image instead. Or maybe even Razor - however I don't have any Razor skills yet so I can't say how to do it.

    But I'd like to hear if there is a specific reason as to why you wish to make the check in the masterpage - 'cause you'll still ned to lookup the image etc.

    /Jan

  • TomLeads 20 posts 42 karma points
    Feb 01, 2011 @ 15:02
    TomLeads
    0

    Hi.

    Only reason is because I have various other things in the masterpage and they all work fine without the need to do any XLST (which I struggle with).

    Happy to use a XLST if necessary.

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Feb 01, 2011 @ 15:28
    Tom Fulton
    2

    Hi Tom,

    Here's logic I used for a checkbox, you could adapt for a media picker and check to see ift he property value is NullOrEmpty:

    <% if (umbraco.presentation.nodeFactory.Node.GetCurrent().GetProperty("yourPropertyAlias").Value.ToString() != "1") { %>
    do something
    <% } else { %>
    do something else
    <% } %>

    See this similar thread that has a similar solution, perhaps a bit more flexible and error-proof:  http://our.umbraco.org/forum/templating/templates-and-document-types/15707-if-statement-on-masterpage?p=0#comment57895

    I would still probably favor a macro though :)

    Thanks,
    Tom

     

  • TomLeads 20 posts 42 karma points
    Feb 09, 2011 @ 16:28
    TomLeads
    1

    Ended up doing this in XLST:

      <xsl:if test="$currentPage/photo1 != ''">
        <li><a href="{umbraco.library:GetMedia($currentPage/photo1,0)/umbracoFile}"><img src="{umbraco.library:GetMedia($currentPage/photo1,0)/umbracoFile}" width="103" height="67" /></a></li>
      </xsl:if>
  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Feb 09, 2011 @ 17:00
    Jan Skovgaard
    0

    Hi Tom

    Happy to hear you found the solution - why did you end up using XSLT instead of C#? (just curious)

    /Jan

  • TomLeads 20 posts 42 karma points
    Feb 11, 2011 @ 09:47
    TomLeads
    0

    Jan, on this project we have a few developers. Some C# guys or more front-end peeps like me, so I don't know C# well enough to do what they do but I can (just about) get my head around XLST.

    Probably not the best way of doing things but Umbraco is a new setup for us so I imagine over time we will create re-usable code snippets in one or the other.

  • Guru Bharadwaj 1 post 21 karma points
    Nov 02, 2012 @ 22:26
    Guru Bharadwaj
    0

    Tom Fulton,

    Thanks so much for posting the checkbox markup. I'm new to Umbraco and you saved me from so much headache. I signed up just to say thanks :)

    cheers,
    Guru

Please Sign in or register to post replies

Write your reply to:

Draft