Processing ember.js tagged html with python

こ雲淡風輕ζ 提交于 2019-12-05 20:31:50

Note, in the trunk version of web2py (which will be released as web2py 2.0 in the next few days), you can now specify custom delimiters for the templates -- so you can change the web2py delimiters so they no longer conflict with the ember.js delimiters. For example, in a model file:

response.delimiters = ['{%', '%}']

Then in your web2py templates, you can do:

{%=P('hello world')%}
<p>{{ember template code}}</p>
{%=P('{{ember template code generated by web2py}}')%}

which will produce:

<p>hello world</p>
<p>{{ember template code}}</p>
<p>{{ember template code generated by web2py}}</p>

Note, response.delimiters is set on each request, so if you don't want to change the web2py delimiters on all pages but only those that include ember code, you can set response.delimiters conditionally (either by setting it in the specific actions that need it, or by checking the requested controller and/or function in a model file). For example, in a model file:

if request.function in ['action1', 'action2', 'action3']:
    response.delimiters = ['{%', '%}']

or in a controller:

def action1():
    response.delimiters = ['{%', '%}']
    [etc.]

It may worth trying an approach with keeping all your Ember.js stuff in separate files and do not mix it with with web2py templates. Fortunately, Ember.js easily allows to do it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!