>
> Enter code here...
>
> // In the mySite.js file
> var myImg = "{{IMG(_src = URL('static','image/myImage.jpg') )}}";
>
Note, the above will only work if mySite.js is a web2py template and the
file is served by calling a web2py action (i.e., it can't be a static
file). Another approach, though, is to leave that variable declaration out
of mySite.js. Instead, include the variable declaration someplace like
layout.html, right before wherever you load the mySite.js file -- that way
the variable will be defined before any code in mySite.js references it.
<script>
var myImg = "{{=IMG(_src = URL('static','image/myImage.jpg'))}}"
</script>
<script src="{{=URL('static', 'js/mySite.js')}}"></script>
This strategy is used in web2py_ajax.html in order to dynamically define a
few variables needed within web2py.js (which is served as a static file).
Yet another option is to make myImg a parameter of your function in
mySite.js and pass it in a web2py template when you call that function:
In mySite.js:
function myFunction(myImg) {
// use myImg variable here
};
In layout.html and/or the page-specific view:
<script src="{{=URL('static', 'js/mySite.js')}}"></script>
<script>
[some code]
myFunction("{{=IMG(_src = URL('static','image/myImage.jpg'))}}");
[more code]
</script>
Anthony
--