Template compile error - invalid template

4 posts, 1 answers
  1. Dimitrij
    Dimitrij avatar
    8 posts
    Member since:
    Apr 2015

    Posted 17 Apr 2015 Link to this post

    Hey guys,

    We have a big problem compiling Kendo templates which contain other Kendo widgets, e.g. a Grid.
    We have the following template (simplified):

    <script id="myTemplate" type="text/x-kendo-template">
      .Columns(columns =>
         columns.Bound(c => c.Name);

    The original template contains other dynamic data-bound values, e.g. "#=Id#"... thus we need a template approach! Now we want to compile this template, because we need to show it as content of a window:

    <script type="text/javascript">
        var myTemplate = kendo.template($("#myTemplate").html());

    This should work fine, but Kendo gives us invalid JavaScript when compiling:

    Invalid template... Generated code: 
    var $kendoOutput, $kendoHtmlEncode = kendo.htmlEncode;with(data){$kendoOutput='<div class="k-widget k-grid" id="myGrid"><table><colgroup><col /></colgroup><thead class="k-grid-header"><tr><th class="k-header" data-field="Name" data-index="0" data-title="Name" scope="col"><span class="k-link">Name</span></th></tr></thead><tbody><tr class="k-no-data"><td colspan="1"></td></tr></tbody></table></div><script>\n\tjQuery(function(){jQuery("';myGrid").kendoGrid({"columns":[{"title":"Name","field":"Name","encoded":true}],"scrollable":false,"autoBind":false,"dataSource":{"type":(function(){if(kendo.data.transports['aspnetmvc-server']){return 'aspnetmvc-server';} else{throw new Error('The kendo.aspnetmvc.min.js script is not included.');}})(),"transport":{"read":{"url":""},"prefix":"channelsAssignGrid-"},"serverPaging":true,"serverSorting":true,"serverFiltering":true,"serverGrouping":true,"serverAggregates":true,"filter":[],"schema":{"data":"Data","total":"Total","errors":"Errors","model":{"fields":{"Name":{"type":"string"}}}}}});});
           ;$kendoOutput+=;}return $kendoOutput;
    In this code, e.g. jQuery("';myGrid") is emitted as wrong JS code...


    Any ideas/solutions for this? I think we're not the first discovering this problem... is there any straight forward solution?


    Thanks, Dimitrij

  2. Answer
    Dimiter Madjarov
    Dimiter Madjarov avatar
    2213 posts

    Posted 21 Apr 2015 Link to this post

    Hello Dimitrij,

    The question is answered on the support thread on the same topic. The ToClientTemplate method of the widget should be invoked.

    Dimiter Madjarov

    See What's Next in App Development. Register for TelerikNEXT.

  3. Rajan
    Rajan avatar
    2 posts
    Member since:
    Jul 2015

    Posted 21 Sep 2016 Link to this post


    I am getting the invalid Template Error while trying to open the nested grid in kendo grid control.
    After lots of findings I have come to know that error is coming because grid's one column contains the data with "#" inside it.
    I have done lots of R&D to handle this but did not succeed.

    Please help me in the concerned issue.
  4. Maria Ilieva
    Maria Ilieva avatar
    4017 posts

    Posted 26 Sep 2016 Link to this post

    Hi Rajan,

    From the error message it seems that the reason for the problem is the AntiXssEncoder which is enabled in the Web.config httpRuntime configuration:

    <httpRuntime targetFramework="4.5" encoderType="System.Web.Security.AntiXss.AntiXssEncoder, System.Web, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
    The spaces in the attributes are encoded and the "#" character is included which breaks the templates parsing. Removing it should resolve the problem. 

    Maria Ilieva
    Telerik by Progress
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top