Using a # in a template

12 posts, 0 answers
  1. John
    John avatar
    30 posts
    Member since:
    Feb 2013

    Posted 21 Mar 2013 Link to this post

    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?
  2. Petyo
    Admin
    Petyo avatar
    2439 posts

    Posted 21 Mar 2013 Link to this post

    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!
  3. Kendo UI is VS 2017 Ready
  4. John
    John avatar
    30 posts
    Member since:
    Feb 2013

    Posted 21 Mar 2013 Link to this post

    Hi Petyo,

    I believe in my case I was using a literal string.  How do I escape it when using a literal string (#= .. # format)
  5. Petyo
    Admin
    Petyo avatar
    2439 posts

    Posted 25 Mar 2013 Link to this post

    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!
  6. John
    John avatar
    30 posts
    Member since:
    Feb 2013

    Posted 26 Mar 2013 Link to this post

    Yes, it's very easy to reproduce.  Here you go: http://jsbin.com/ivivac/1/
  7. Petyo
    Admin
    Petyo avatar
    2439 posts

    Posted 28 Mar 2013 Link to this post

    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!
  8. John
    John avatar
    30 posts
    Member since:
    Feb 2013

    Posted 28 Mar 2013 Link to this post

    Here, look at this version: http://jsbin.com/ivivac/3/
  9. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 28 Mar 2013 Link to this post

    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!
  10. John
    John avatar
    30 posts
    Member since:
    Feb 2013

    Posted 28 Mar 2013 Link to this post

    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.
  11. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 28 Mar 2013 Link to this post

    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!
  12. John
    John avatar
    30 posts
    Member since:
    Feb 2013

    Posted 28 Mar 2013 Link to this post

    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."
  13. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 28 Mar 2013 Link to this post

    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!
Back to Top
Kendo UI is VS 2017 Ready