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 3325 posts 11170 karma points MVP 5x 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 3008 posts 13221 karma points MVP 7x 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

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies