Are there beautiful way to add variable in script?
I know that ways:
1. It's very simple, but it's not useful to write many javascript code in
controller.
controller.py
XML('<script type="text/javascript">console.log('+myVariable+');</script>'),
2. In that case I have 2 script files in HTML. First contain my variable,
second contain javascript code and get variable from first. It's not good
too.
controller.py
def index():
jsScript = XML('<script src="'+URL('static','js\myScript.js')+'"
type="text/javascript"></script>')
myVariable = '[[1,1,"text text"],[1,2,"text text"],...,[12,20,"tex
text"]]'
return dict(jsScript=jsScript,myVariable=myVariable)
index.html
<script>
var myVariable = '{{=myVariable}}';
</script>
{{=jsScript}}
Also I can write all js code in first script tag, but that practice is not
normal too. I want have python files with python code, html files with html
and js files with javascript. I tried add {{=myVariable}} in js file, but
it's not work, as I think becouse it's static folder.
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/web2py/a7a1ac4a-ddb3-45e9-aa71-3afae84aee2e%40googlegroups.com.