On Monday, July 29, 2019 at 3:18:53 AM UTC-7, Константин Комков wrote:
>
> 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.
>
>
Check out the ASSIGNJS() helper.
<URL:http://web2py.com/books/default/chapter/29/05/the-views#ASSIGNJS>
/dps
--
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/1a59d835-0c91-435b-9907-d65fbb878037%40googlegroups.com.