This is a migrated thread and some comments may be shown as answers.
useWithBlock explanation
5 Answers 115 Views
This is a migrated thread and some comments may be shown as answers.
Redsquare
Top achievements
Rank 1
Redsquare asked on 22 Feb 2012, 11:33 PM
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

 

5 Answers, 1 is accepted

Sort by
0
Accepted
Atanas Korchev
Telerik team
answered on 23 Feb 2012, 09:04 AM
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!
0
Redsquare
Top achievements
Rank 1
answered on 23 Feb 2012, 09:52 AM
Makes sense. Thanks for the quick response.
0
Joel
Top achievements
Rank 1
answered on 03 Mar 2012, 10:40 PM
Great question and equally good response.
0
David
Top achievements
Rank 1
answered on 04 Dec 2012, 08:05 PM
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});
0
Atanas Korchev
Telerik team
answered on 05 Dec 2012, 07:37 AM
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!
Asked by
Redsquare
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Redsquare
Top achievements
Rank 1
Joel
Top achievements
Rank 1
David
Top achievements
Rank 1
Share this question
or