useWithBlock explanation

6 posts, 1 answers
  1. Redsquare
    Redsquare avatar
    13 posts
    Member since:
    Jun 2012

    Posted 22 Feb 2012 Link to this post

    I have seen a few blog posts from Todd refer to the speed of templates especially when you set the useWithBlock to false. However without explanation this is set to true by default. Can you show me examples of when I do and do not need this. The docs do not even mention this setting which seems an odd omission due to the speed hype built via the blog posts.

    Thanks

     
  2. Answer
    Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 23 Feb 2012 Link to this post

    Hello,

     I created a jsFiddle demo which shows the difference in the generated code:

     
    By default a with(data) block is created which allows the developer to use only the field name in the template expressions:   "#= foo# instead of "#= data.foo#". The with block removes the hassle to type in "data." every time but would cause a performance decrease if the template is used a lot (a few hundred times).

    Regards,
    Atanas Korchev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Kendo UI is VS 2017 Ready
  4. Redsquare
    Redsquare avatar
    13 posts
    Member since:
    Jun 2012

    Posted 23 Feb 2012 Link to this post

    Makes sense. Thanks for the quick response.
  5. Joel
    Joel avatar
    78 posts
    Member since:
    Oct 2012

    Posted 03 Mar 2012 Link to this post

    Great question and equally good response.
  6. David
    David avatar
    60 posts
    Member since:
    Nov 2012

    Posted 04 Dec 2012 Link to this post

    Is there a way to set the template to disable useWithBlock outside of javascript?

    I would like to do something like 
    <script type="text/x-kendo-template" id="sampleTemplate" data-use-with-block="false">
     #: data.someValue #
    </script>

    or perhaps with 1 line of javascript make it so templates default to useWithBlock  set to false instead of true, instead of being forced to write javascript to do:

    var tmp = kendo.template($("#sampleTemplate").html(), { useWithBlock: false});
  7. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 05 Dec 2012 Link to this post

    Hello David,

     There is an undocumented way to globally set the useWithBlock setting. However this may break some widgets. Still you can try it to see if it would work in your case. Here is a demo showing how to do that: http://jsbin.com/evicef/1/edit

    Regards,
    Atanas Korchev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top
Kendo UI is VS 2017 Ready