# Templates

The DropDownTree provides full control over the way a node, a selected value, a pop-up header, or footer is rendered through the Kendo UI for jQuery templates.

For more information on the capabilities and syntax of the templates, refer to this [documentation article](https://docs.telerik.com/kendo-ui/framework/templates/overview). For a runnable example, refer to the [dem on using templates in the DropDownTree](https://demos.telerik.com/aspnet-core/dropdowntree/templates).

## Basic Usage

The following example demonstrates how to customize the DropDownTree by declaring an inline string.

```Razor HtmlHelper
    
    @(Html.Kendo().DropDownTree()
        .Name("dropdowntree")
        .Template("<span><h3>#: data.text #</h3></span>")
        .DataSource(source =>
        {
            source.Read(read => read.Action("Read_TemplateData", "DropDownTree"));
        })
    )
```

```Razor TagHelper
    <kendo-dropdowntree template="<span><h3>#: data.text #</h3></span>" name="dropdowntree">
        <hierarchical-datasource>
            <schema>
                <hierarchical-model id="id"></hierarchical-model>
            </schema>
            <transport>
                <read url=@Url.Action("Read_TemplateData","DropDownTree") />
            </transport>
        </hierarchical-datasource>
    </kendo-dropdowntree>
```

The following example demonstrates how to customize the DropDownTree by referencing a script tag by its `id`.

```Razor HtmlHelper
    
    <script id="dropdowntree-template" type="text/kendo-ui-template">
        #: item.text #
    </script>

    
    @(Html.Kendo().DropDownTree()
        .Name("dropdowntree")
        .TemplateId("dropdowntree-template")
        .DataSource(source =>
        {
            source.Read(read => read.Action("Read_TemplateData", "DropDownTree"));
        })
    )
```

```Razor TagHelper
    
    <script id="dropdowntree-template" type="text/kendo-ui-template">
        #: item.text #
    </script>

    
    <kendo-dropdowntree template-id="dropdowntree-template" name="dropdowntree">
        <hierarchical-datasource>
            <schema>
                <hierarchical-model id="id"></hierarchical-model>
            </schema>
            <transport>
                <read url=@Url.Action("Read_TemplateData","DropDownTree") />
            </transport>
        </hierarchical-datasource>
    </kendo-dropdowntree>
```

## Item Template

The item template manages the way the nodes in the DropDownTree are rendered.

The following example demonstrates how to define an item template and how to evaluate it against the `dataItem`.

```Razor HtmlHelper
    
    <script id="dropdowntree-template" type="text/kendo-ui-template">
        #: item.text #
    </script>

    
    @(Html.Kendo().DropDownTree()
        .Name("dropdowntree")
        .TemplateId("dropdowntree-template")
        .DataSource(source =>
        {
            source.Read(read => read.Action("Read_TemplateData", "DropDownTree"));
        })
    )
```

```Razor TagHelper
    
    <script id="dropdowntree-template" type="text/kendo-ui-template">
        #: item.text #
    </script>

    
    <kendo-dropdowntree template-id="dropdowntree-template" name="dropdowntree">
        <hierarchical-datasource>
            <schema>
                <hierarchical-model id="id"></hierarchical-model>
            </schema>
            <transport>
                <read url=@Url.Action("Read_TemplateData","DropDownTree") />
            </transport>
        </hierarchical-datasource>
    </kendo-dropdowntree>
```

## Value Template

The value template manages the way the selected items in the input area of the DropDownTree are rendered.

```Razor HtmlHelper
    
    <script id="dropdowntree-value-template" type="text/kendo-ui-template">
        <span class="k-sprite #: spriteCssClass #"></span>
        <span> #: data.text # </span>
    </script>

    
    @(Html.Kendo().DropDownTree()
        .Name("dropdowntree")
        .ValueTemplateId("dropdowntree-value-template")
        .DataSpriteCssClassField("spriteCssClass")
        .DataSource(source =>
        {
            source.Read(read => read.Action("Read_TemplateData", "DropDownTree"));
        })
    )
```

```Razor TagHelper
    <script id="dropdowntree-value-template" type="text/kendo-ui-template">
        <span class="k-sprite #: spriteCssClass #"></span>
        <span> #: data.text # </span>
    </script>

    
    <kendo-dropdowntree dataspritecssclassfield="spriteCssClass" value-template-id="dropdowntree-value-template" name="dropdowntree">
        <hierarchical-datasource>
            <schema>
                <hierarchical-model id="id"></hierarchical-model>
            </schema>
            <transport>
                <read url=@Url.Action("Read_TemplateData","DropDownTree")/>
            </transport>
        </hierarchical-datasource>
    </kendo-dropdowntree>
```

## Header Template

The header template manages the way the pop-up header of a DropDownTree is rendered.

```Razor HtmlHelper
    
    <script id="dropdowntree-header-template" type="text/kendo-ui-template">
        <strong>Header</strong>
    </script>

    
    @(Html.Kendo().DropDownTree()
        .Name("dropdowntree")
        .HeaderTemplateId("dropdowntree-header-template")
        .DataSource(source =>
        {
            source.Read(read => read.Action("Read_TemplateData", "DropDownTree"));
        })
    )
```

```Razor TagHelper
    
    <script id="dropdowntree-header-template" type="text/kendo-ui-template">
        <strong>Header</strong>
    </script>

    
    <kendo-dropdowntree header-template-id="dropdowntree-header-template" name="dropdowntree">
        <hierarchical-datasource>
            <schema>
                <hierarchical-model id="id"></hierarchical-model>
            </schema>
            <transport>
                <read url=@Url.Action("Read_TemplateData","DropDownTree")/>
            </transport>
        </hierarchical-datasource>
    </kendo-dropdowntree>
```

## Footer Template

The footer template manages the way the pop-up footer of a DropDownTree is rendered. The footer is re-rendered on every change of the Data Source. The context of the template is the widget itself.

```Razor HtmlHelper
    
    <script id="dropdowntree-footer-template" type="text/x-kendo-template">
        Total <strong>#: instance.dataSource.total() #</strong> items found
    </script>

    
    @(Html.Kendo().DropDownTree()
        .Name("dropdowntree")
        .FooterTemplateId("dropdowntree-footer-template")
        .DataSource(source =>
        {
            source.Read(read => read.Action("Read_TemplateData", "DropDownTree"));
        })
    )
```

```Razor TagHelper
    
    <script id="dropdowntree-footer-template" type="text/x-kendo-template">
        Total <strong>#: instance.dataSource.total() #</strong> items found
    </script>

    
    <kendo-dropdowntree footer-template-id="dropdowntree-footer-template" name="dropdowntree">
        <hierarchical-datasource>
            <schema>
                <hierarchical-model id="id"></hierarchical-model>
            </schema>
            <transport>
                <read url=@Url.Action("Read_TemplateData","DropDownTree")/>
            </transport>
        </hierarchical-datasource>
    </kendo-dropdowntree>
```

## No-Data Templates

The DropDownTree displays `noDataTemplate` in the popup when the data source is empty.

```Razor HtmlHelper
    
    <script id="dropdowntree-nodata-template" type="text/x-kendo-template">
        <strong>No Data!</strong>
    </script>

    
    @(Html.Kendo().DropDownTree()
        .Name("dropdowntree")
        .Filter(FilterType.Contains)
	    .NoDataTemplateId("dropdowntree-nodata-template")
        .DataSource(source =>
        {
            source.Read(read => read.Action("Read_TemplateData", "DropDownTree"));
        })
    )
```

```Razor TagHelper
    
    <script id="dropdowntree-nodata-template" type="text/x-kendo-template">
        <strong>No Data!</strong>
    </script>

    
    <kendo-dropdowntree no-data-template="dropdowntree-nodata-template" name="dropdowntree">
        <hierarchical-datasource>
            <schema>
                <hierarchical-model id="id"></hierarchical-model>
            </schema>
            <transport>
                <read url=@Url.Action("Read_TemplateData","DropDownTree")/>
            </transport>
        </hierarchical-datasource>
    </kendo-dropdowntree>
```

## See Also

* [Templates in the DropDownTree HtmlHelper for ASP.NET Core (Demo)](https://demos.telerik.com/aspnet-core/dropdowntree/templates)
* [Server-Side API](https://www.telerik.com/aspnet-core-ui/documentation/api/dropdowntree)
