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

StackOverflow https://stackoverflow.com/questions/10973024

  •  13-06-2021
  •  | 
  •  

سؤال

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? ;)

هل كانت مفيدة؟

المحلول

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?

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top