bottle icon indicating copy to clipboard operation
bottle copied to clipboard

New code block template syntax conflicts with underscore.js syntax

Open inkvizitor opened this issue 12 years ago • 3 comments

In Bottle 0.12-dev, rendering template which has line beginning with '<%' is producing SyntaxError . At least in 0.11.3, problem was not present. '<%= %>' is syntax for Underscore templates.

>>> bottle.__version__
'0.12-dev'
>>> from bottle import SimpleTemplate
>>> tpl = SimpleTemplate('<%=bla %>')
>>> tpl.render()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "bottle.py", line 3131, in render
    self.execute(stdout, env)
  File "bottle.py", line 3118, in execute
    eval(self.co, env)
  File "bottle.py", line 184, in __get__
    value = obj.__dict__[self.func.__name__] = self.func(obj)
  File "bottle.py", line 3085, in co
    return compile(self.code, self.filename or '<string>', 'exec')
  File "<string>", line 1
    =bla
    ^
SyntaxError: invalid syntax

inkvizitor avatar Jun 24 '13 13:06 inkvizitor

0.12 adds a syntax for code blocks, that seems to be in conflict with underscore.js. It will be possible to change the syntax for bottle templates, but that API is not public yet. I'll keep this bug open as a reminder.

defnull avatar Jun 25 '13 15:06 defnull

the {{var }} syntax also interfere with vue.js I saw the document mentioned the template token is customizable (http://bottlepy.org/docs/dev/stpl.html "If you find yourself to escape a lot, consider using custom tokens." ) but its didn't explain how this can be done. Have to look into the source to figure out the parameter: template( "sometpl", template_settings={"syntax" :'<% %> % {| |}'} ) Could you add the parameter to the document ?

zcattacz avatar Apr 05 '16 00:04 zcattacz

It's 2016, and many of the things in underscore.js have found their way into ES5 and ES6. So the fix might not be a a fix at all. Rather, developers today should opt for using more modern JS over underscore JS. As for the last comment of @zcattacz, can you just open this PR? Other wise I will do it.

oz123 avatar Aug 28 '16 17:08 oz123