views:

51

answers:

3

Hi,

i'm implementing a web app using web2py and jquery. I want to use the jquery templating plugin (http://github.com/jquery/jquery-tmpl) but the plugin uses the same notation for templates as web2py ( {{ code }} and collides with web2py templating. Is there any way i can disable web2py templating or escape the {{ and }} parts ?

Thank you !

+1  A: 

You can disable web2py templating my simply haing the controller functions return a string instead. You may also want to consider this option: in jquery-tmpl.js you can replace

/{{(\/?)(\w+|.)(?:\((.*?)\))?(?: (.*?))?}}/g

with

/{%(\/?)(\w+|.)(?:\((.*?)\))?(?: (.*?))?%}/g

and use {%...%} in pace of {{...}} so no more conflict with web2py syntax. Similarly we have add an option to web2py to switch syntax there. If this is critical bring it up on the web2py mailing list.

mdipierro
I think for switching syntax in web2py we should wait for what templating will get into jquery core.
MeanShift
web2py cannot switch because we promis backward compatibility. We can give different options. Anyway, I agree. let's wait and see. Using {{..}} would not be a good idea for them since it conflicts with JS.
mdipierro
A: 

I also had to replace

/\${([^}]*)}/g, "{{= $1}} 

with

/\${([^}]*)}/g, "{%= $1%}

but after that it works fine. Thank you!

MeanShift
A: 

Anyway, I just implemented arbitrary delimiters in web2py trunk. Now you can do in a controller:

def render(filename,**variables):
    context = globals()
    context.update(variables)
    from gluon.template import render
    return render(filename=os.path.join(request.folder,'views',filename),
                  path=os.path.join(request.folder,'views'),
                  context=context,delimiters=('{%','%}'))

def index():
    return render('default/index.html',message='hello world')

and in default/index.html:

{%=message%}

This is very new (5 mins ago) so give it a try and let me know if it works for you. Please follow up on our mailing list.

mdipierro