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

Using a # in a template

11 Answers 532 Views
Templates
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 21 Mar 2013, 05:21 PM
Hi All

In my application we are using backbone.js for MV* type functionality.  IT performs navigation events based on hash (#) in a URL.  So for example entering in #profile brings up your profile.  We are using a KendoUI template in a grid (since I couldn't get other templates to work right).  Is there anyway to escape a # that may appear in the template?

11 Answers, 1 is accepted

Sort by
0
Petyo
Telerik team
answered on 21 Mar 2013, 06:59 PM
Hi John,

The getting started / templates article in our documentation describes the escaping syntax in strings and script templates in details. 

Regards,
Petyo
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
John
Top achievements
Rank 1
answered on 21 Mar 2013, 09:26 PM
Hi Petyo,

I believe in my case I was using a literal string.  How do I escape it when using a literal string (#= .. # format)
0
Petyo
Telerik team
answered on 25 Mar 2013, 01:00 PM
Hello,

Unless I am missing something, I don't think you need any sort of a special treatment for the strings in the template (escaping # symbols, etc). If you still experience troubles with this, can you prepare a small example? We will check it out and do our best to help. 

All the best,
Petyo
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
John
Top achievements
Rank 1
answered on 26 Mar 2013, 04:58 PM
Yes, it's very easy to reproduce.  Here you go: http://jsbin.com/ivivac/1/
0
Petyo
Telerik team
answered on 28 Mar 2013, 08:01 AM
Hi,

I am not sure what is the problem in the bin provided. Can you please elaborate a bit?

Regards,
Petyo
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
John
Top achievements
Rank 1
answered on 28 Mar 2013, 12:45 PM
Here, look at this version: http://jsbin.com/ivivac/3/
0
Atanas Korchev
Telerik team
answered on 28 Mar 2013, 01:47 PM
Hello John,

 This is not a valid template. The #= # expression should contain a valid JavaScript identifier which "#" by itself isn't. Here is the updated demo with a valid template and values containing "#": http://jsbin.com/ivivac/5/edit

All the best,
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
John
Top achievements
Rank 1
answered on 28 Mar 2013, 01:51 PM
Here's an updated version that's closer to what we're trying to do.

http://jsbin.com/ivivac/6/

Basically, we want # to appear in front of the value in the model of the datasource.
0
Atanas Korchev
Telerik team
answered on 28 Mar 2013, 01:57 PM
Hello John,

 In that case you just need to put the # outside of the #= # expression:

  rowTemplate:kendo.template("<tr><td>\\# #= value #</tr>"),

Here is the updated example: http://jsbin.com/ivivac/7/edit

All the best,
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
John
Top achievements
Rank 1
answered on 28 Mar 2013, 02:10 PM
But then # is outside of the literal expression, going back to my prior post; "There is no way to put a # in a literal expression."
0
Atanas Korchev
Telerik team
answered on 28 Mar 2013, 02:17 PM
Hello John,

 I provided a working version of the demo. Did you check it out? It shows how to escape a "#" in a template definition. And yes, you cannot have "#" inside a "#= #" expression.

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!
Tags
Templates
Asked by
John
Top achievements
Rank 1
Answers by
Petyo
Telerik team
John
Top achievements
Rank 1
Atanas Korchev
Telerik team
Share this question
or