This is a migrated thread and some comments may be shown as answers.

Cannot define template as data-template attribute

5 Answers 93 Views
Templates
This is a migrated thread and some comments may be shown as answers.
Grant
Top achievements
Rank 2
Iron
Iron
Veteran
Grant asked on 13 May 2020, 10:54 AM

Hi team,

As the question says, Im trying to define my template content as part of an html data attribute, see dojo: https://dojo.telerik.com/UxAPOXeV

But i get a syntax error when the widget is initialized.

Please advise.

Thanks,
Grant

5 Answers, 1 is accepted

Sort by
0
Accepted
Tsvetomir
Telerik team
answered on 15 May 2020, 09:38 AM

Hi Grant,

Thank you for the provided Dojo sample that demonstrates the syntax error. Indeed, within the data-template attribute, an external kendo.template has to be passed. Here is an example:

data-template="template"
// ... ...
 <script type="text/kendo-x-tmpl" id="template">
    <div>
        Item template for #:name#
    </div>
 </script>

Check out the modified sample here:

https://dojo.telerik.com/ezofEhUm

I hope this helps.

 

Regards,
Tsvetomir
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
Grant
Top achievements
Rank 2
Iron
Iron
Veteran
answered on 15 May 2020, 10:11 AM

Thanks Tsvetomir,

This is perfect.Please can you link me to the docs where this is covered, I couldn't find this particular scenario.

Also see that sometimes the script type is "text/kendo-x-tmpl" and sometimes its "text/kendo-x-template", is one being deprecated, is one more correct than the other, why the change, does it matter?

Thanks a bunch,
Grant

0
Grant
Top achievements
Rank 2
Iron
Iron
Veteran
answered on 15 May 2020, 01:29 PM

I have another related question.

Please look at this dojo, https://dojo.telerik.com/ikebUlIY/4
Why does Template #1 work but Template #2 has syntax errors?

Thanks


0
Grant
Top achievements
Rank 2
Iron
Iron
Veteran
answered on 15 May 2020, 01:30 PM
Sorry, meant https://dojo.telerik.com/ikebUlIY/5
0
Tsvetomir
Telerik team
answered on 15 May 2020, 01:57 PM

Hi Grant,

There is a difference between the "#=#" and "##" syntax. The first one is used when a template should be built based on a specific field or object, however, JavaScript logic will not be executed. The second one is used when JavaScript logic has to be executed - in the current case, the placeholders "{0} {1}" and the kendo.format() method require JavaScript. Alternatively, you could use the following:

<script type="text/x-kendo-template" id="groupByName-templateHeader2" data-th-inline="javascript">
         # return kendo.format("Total Tasks for {0}: {1}", value, aggregates.tasks.sum); #
    </script>

More information on the templates could be found here:

 

Regards,
Tsvetomir
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Tags
Templates
Asked by
Grant
Top achievements
Rank 2
Iron
Iron
Veteran
Answers by
Tsvetomir
Telerik team
Grant
Top achievements
Rank 2
Iron
Iron
Veteran
Share this question
or