x First time here? Check out the FAQ
Join us a the Umbraco event of the year - get your Codegarden 14 early bird ticket today
  • Avatar245posts267karma

    razor in template

    hetaurhet started this topic March 7, 2012 @ 03:56

    can I write razor code in template...? something like...

    <umbraco:Macro runat="server" language="cshtml"
    <
    ul>
     
       @{
    var
    selected = Array.IndexOf(Request.Url, 'competition') >= 0 ? " class=\"selected\"" : "";
    <li@Html.Raw(selected)>
    var selected1 = Array.IndexOf(Request.Url, 'gallery') >= 0 ? " class=\"selected\"" : "";
    <li@Html.Raw(selected1)
        }
    </
    ul>
    </umbraco:Macro>

    as just now this is giving me error... randering script error...


  • Avatar167posts260karma
    Comment with ID: 110191
    gilad posted this reply March 7, 2012 @ 04:01

    you can write razor in template like you did.

    you have some problem with the macro code.

    what should be the result?

    you are open new LI before closing the first one.

    and the second LI tag is not close


  • Avatar245posts267karma
    Comment with ID: 110240
    hetaurhet posted this reply March 8, 2012 @ 06:12

    u r right... actually I want to set selected class in particular li tag by checking if url contains a particular word

    here is the modifdied code.. but still showing error...

    <div class="talent-menu-mid">
    <umbraco:Macro runat="server" language="cshtml">  
    <ul>
    @{
      string selected = Array.IndexOf(@Model.Path, 'competition') >= 0 ? " class=\"selected\"" : "";
      <li@Html.Raw(selected)><a href="/talent-corner/competition/" >Competition</a></li>
      string selected1 = Array.IndexOf(@Model.Path, 'Participate') >= 0 ? " class=\"selected\"" : "";
      <li@Html.Raw(selected1)><a href="/talent-corner/participate/">Participate</a></li>
      string selected2 = Array.IndexOf(@Model.Path, 'Gallery') >= 0 ? " class=\"selected\"" : "";  
      <li@Html.Raw(selected2)><a href="/talent-corner/gallery/">Gallery</a></li>
    }   
    </ul>
    </umbraco:Macro>
    </div>

    can you correct the code.. where am I going wrong?


  • Avatar245posts267karma
    Comment with ID: 110366
    hetaurhet posted this reply March 9, 2012 @ 05:25

    anybody.. any clue.. what's going wrong?


Please login or Sign up To post replies