Get Umbraco Certified in October

5 courses in 4 different countries across 2 continents leaves no excuse.

Attend courses in the Netherlands, UK, USA and at Umbraco HQ in Denmark.

See the schedule and read more about our training here.

Copied to clipboard

Flag this post as spam?

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

  • hetaurhet 245 posts 267 karma points
    Mar 07, 2012 @ 15:56

    razor in template

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

    <umbraco:Macro runat="server" language="cshtml"
    selected = Array.IndexOf(Request.Url, 'competition') >= 0 ? " class=\"selected\"" : "";
    var selected1 = Array.IndexOf(Request.Url, 'gallery') >= 0 ? " class=\"selected\"" : "";

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

  • gilad397 karma points
    Mar 07, 2012 @ 16: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

  • hetaurhet267 karma points
    Mar 08, 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">  
      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>

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

  • hetaurhet267 karma points
    Mar 09, 2012 @ 05:25

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

Please Sign in or register to post replies

Write your reply to:

Draft is the community mothership for Umbraco, the open source cms. With a friendly forum for all your questions, a comprehensive documentation and a ton of packages from the community. This site is running Umbraco version 7.3.0