Copied to clipboard

Flag this post as spam?

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


  • shine 43 posts 83 karma points
    May 28, 2013 @ 10:39
    shine
    0

    how we can write condition in template

    here is my code that i write in umbraco templatebut its return error plz tell me where is i'm wrong


        <% if ((umbraco.library.GetItem('pageheaderLink') == '') {

    <umbraco:Item field="pageheader" runat="server" />

    <% } else { %>

    <a href='<umbraco:Item field="pageheaderLink" runat="server" />'><umbraco:Item field="pageheader" runat="server" /></a>

    <% } %>

  • Dave Woestenborghs 3504 posts 12134 karma points MVP 9x admin c-trib
    May 28, 2013 @ 10:41
    Dave Woestenborghs
    0

    There is a one ( too many in the if-statement.

     

    Dave

  • shine 43 posts 83 karma points
    May 28, 2013 @ 10:48
    shine
    0

    budy plz guide for the correct format for above code

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Jun 06, 2013 @ 11:41
    Jeavon Leopold
    0

    Hi Shine,

    It would be like this: 

     <% if ((umbraco.library.GetItem("pageheaderLink") == "")) { %>
      <umbraco:Item field="pageheader" runat="server" />
    <% } else { %>
     <a href='<umbraco:Item field="pageheaderLink" runat="server" />'><umbraco:Item field="pageheader" runat="server" /></a>
    <% } %>  

     However, I would recommend that you use a inline Razor macro instead, this would be like this:

    <umbraco:Macro runat="server" language="cshtml">
    @{
        if (!Model.HasValue("pageheaderLink")){            
          <span>@Model.pageheader</span>
        } else {
          <a href="@Model.pageheaderLink">@Model.pageheader</a>
        }
    }
    </umbraco:Macro>

    Thanks,

    Jeavon

Please Sign in or register to post replies

Write your reply to:

Draft