Search code examples
javascriptrazorrythm

Is there a templating language similar to Razor for pure Javascript applications?


I'm in love with razor templates in .NET MVC 3. Is there anything close for javascript?

I'd be looking for something where I could use something like this:

@if(bla)
{
  <span>my html</span>
}

I already know something similar exists fo Java. What about Javascript? ;)


Solution

  • Maybe Knockout.js is what you're looking for.

    You can do conditionals like this

    <!-- ko if: $data === app.viewModel.admin.home.paging.page() -->
        <span data-bind="html: $data"></span>
    <!-- /ko -->
    

    Source: Does conditional logic work under the default knockout.js 2.0 template engine?