Version

Creating a Nested Blocks Template

Topic Overview

Purpose

This topic demonstrates how to create nested blocks template using the templating engine

Required background

The following table lists the topics required as a prerequisite to understanding this topic.

In this topic

This topic contains the following sections:

Creating a Nested Blocks Template

Introduction

In this example a nested block template is created and the result is appended to an html table.

Preview

The following screenshot demonstrates how nested properties are combined into two groups – Name and Age, while in the data source they are three – firstName, lastName and age. The templating engine iterates through each item into teamMembers array. As a result of applying the nested blocks template implemented in this example.

Prerequisites

To complete the procedure you need the following:

  • An empty html page with reference to the minimal set of needed js files for the templating engine. (For details, refer to Adding igTemplating References )

Steps

The following steps demonstrate how to create basic substitution template.

  1. Add and apply the row template using templating engine

    1. Add sample data and row template to the page:

      In JavaScript:

       <script type="text/javascript">
       var team = [{
             teamMembers: [
                { firstName: "Joseph", lastName: "Sommers", age: 35 },
                { firstName: "Anna ", lastName: "Paterson", age: 25}, 
                { firstName: "Mark", lastName: "Smith", age: 40}      ]
       }];
       var template = '{{each ${teamMembers} }}' +
       '<tr><td><b>Name: </b>${teamMembers.firstName} ${teamMembers.lastName}</td>' +'<td><b>Age: </b>${teamMembers.age}</td></tr>' +
       '{{/each}}';
       </script>
      

      In HTML:

       <body>
       <table id="resultTable" style="border: 1px solid #000;"></table>
       </body>
      
    2. Apply the template and append the result to the html table

      In JavaScript:

       <script type="text/javascript">
       $(document).ready(function () {
             var result = $.ig.tmpl(template, team);
             $('#resultTable').html(result);
       });
       </script>
      
  2. (Optional) Verify the result

    Save the file and double click to preview the result

Related Content

Topics

The following topics provide additional information related to this topic.

Samples

The following samples provide additional information related to this topic.

  • Nested Templates: This sample demonstrates how nested templates are possible using the Infragistics Templating Engine. In the following scenario each feature of the Infragistics Templating Engine is used to iterate through the movies collection from the data source and unordered list is created as an output in the last column.

View on GitHub