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
Thanks
5 Answers, 1 is accepted
0
Accepted
Hello,
Atanas Korchev
the Telerik team
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).
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});
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
Hello David,
Atanas Korchev
the Telerik team
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!