Book Image

Getting Started with Knockout.js for .NET Developers

By : Andrey Ankshin
Book Image

Getting Started with Knockout.js for .NET Developers

By: Andrey Ankshin

Overview of this book

Table of Contents (14 chapters)
Getting Started with Knockout.js for .NET Developers
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Different templating approaches


Knockout.js provides you with great opportunities to write reusable code. Another important task is writing reusable markup. This task can be solved with the help of named templates. It is a very convenient way to create a flexible view. We already discussed one template approach with the control flow bindings (foreach, if, and with). In this section, we will discuss another approach: the string-based templates. They help you connect Knockout.js with third-party templates' engines. The following parameters can be useful in such a case:

  • name: This is the name of the defined template

  • data: This is a model for the template

  • if: This is a condition under which the template will be rendered

  • foreach: This is a model for the template in the "foreach" mode

  • as: This is an alias for the template in the "foreach" mode

As usual, we will learn about the template mechanism with examples.

A simple named template

In the first example, we will just cover how to create a simple...