Friday, October 25, 2013

Variable placeholder conflict between AngularJs and Jinja2 template

It's quite common that in web page templates (diango or jinja2 templates) brackets "{{}}" are used as placeholders for template variables. When people want to use angularjs in those template files, angularjs might not work properly because it also uses "{{}}" to bind data model. A workaround for this is to redefine the templates; an example for Jinja2 template is as follows:
JINJA_ENVIRONMENT=jinja2.Environment( loader=jinja2.FileSystemLoader(os.path.dirname(__file__)), extensions=['jinja2.ext.autoescape'], variable_start_string='((', variable_end_string='))', autoescape=True)
After this step is done, in the template files, "(())" refers to template variables, and "{{}}" refers to AngularJs data model.