Oh Noes! template parsing conflict!

34 views
Skip to first unread message

blackthorne

unread,
Jul 18, 2011, 9:23:54 PM7/18/11
to web2py-users
While editing a javascript code to adapt the behavior of an addthis
button I got something unexpected...
Checkout this JS code and thing about web2py template code:
var addthis_share = {
templates: { twitter: 'check out {{title}} @ {{url}}' }
}


First try:
templates: { twitter: 'check out '{{="{{title}} @ {{url}}"}}' }

if real parsing was going on here, this should work but probably the
template engine just uses regular expressions to find the ending
{{ mark after the beginning {{ and ignores everything else. So, it is
a fail...

Second try:
templates: { twitter: 'check out
'{{=chr(123)+chr(123)+'title'+chr(125)+chr(125)+' @
'+chr(123)+chr(123)+'url'+chr(125)+chr(125)}}' }

ok, this is sort of hacking the own framework but it works. It's ugly
but it works

Can we make it prettier without throwing this to a javascript file?

Vasile Ermicioi

unread,
Jul 18, 2011, 9:29:01 PM7/18/11
to web...@googlegroups.com
you can change template delimiters 

in controller
def myf():
    return response.render('myf.html', delimiters=('{%','%}'))

now you can use python code in myf.html 

{%if True:%}It works! {%pass%}

Anthony

unread,
Jul 18, 2011, 10:56:17 PM7/18/11
to web...@googlegroups.com
I'm not sure you can pass 'delimiters' to response.render() -- you might have to follow this method: https://groups.google.com/d/topic/web2py/4IFFE-7vq1I/discussion.
 
Anthony
Reply all
Reply to author
Forward
0 new messages