# 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

    Hi

    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 ... ) #
    </script>
    kendo.bind(jQuery('#mytemplate'), cardsViewModel);
    Likewise, as part of a view template:
    var cards = new kendo.View('mytemplate', {
                wrap: false,
                model: cardsViewModel
            });
            jQuery('#targetelement').html(cards.render());
    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">
                   </div>
    <script type="text/x-kendo-template" id="my-template">
        <span data-bind="text: this"></span>
    </script>

  2. Petur Subev
    Admin
    Petur Subev avatar
    1677 posts
    Member since:
    Sep 2012

    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:

    http://docs.kendoui.com/getting-started/framework/templates/overview

    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
    Telerik

    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!

Back to Top