# javascript code # in template from kendo.bind or kendo.view

2 posts, 0 answers
  1. Kieren
    Kieren avatar
    6 posts
    Member since:
    Jun 2013

    Posted 26 Aug 2013 Link to this post


    Is it possible to write JavaScript code in a template - and instantiate the template implicitly by using kendo.Bind OR kendo.View?
    <script type="text/x-kendo-template" id="mytemplate">
    # for (int i ... ) #
    kendo.bind(jQuery('#mytemplate'), cardsViewModel);
    Likewise, as part of a view template:
    var cards = new kendo.View('mytemplate', {
                wrap: false,
                model: cardsViewModel
    Because whenever I try and use #, #= or #:, it just renders as text :(
    Leads me to believe it only works if you explicitly instantiate as a template:
    var inlineTemplate = kendo.template($("#javascriptTemplate").html());
    I've only been able to use this notation to successfully render items:
    <div data-template="my-template" data-bind="source: myItems">
    <script type="text/x-kendo-template" id="my-template">
        <span data-bind="text: this"></span>
  2. Petur Subev
    Petur Subev avatar
    1882 posts

    Posted 28 Aug 2013 Link to this post

    Hello Kieren,

    You cannot instantiate template when using kendo.bind / kendo.init. To create template you need to do it like explained here:


    The only exceptional cases when the templates are instantiated automatically (if you pass string instead of actual template) are when widgets have templates like the listview does.

    Kind Regards,
    Petur Subev
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top