On Saturday, June 23, 2018 at 11:05:35 PM UTC-4, Jonsubs wrote:
>
> Hi everyone,
> I'm a web2py newbie and I'm trying to use a third party JS library 
> (chessboard.js from http://www.chessboardjs.com/). The library is used to 
> show a chessboard in the webpage. It does use some images to show the chess 
> pieces, the javascript has a relative path in the code:
>
> cfg.pieceTheme = 'img/chesspieces/wikipedia/{piece}.png';
>

This is relative to the path of the current file (which is the JS file 
itself), so you should put the /img folder inside the /static/js folder.
 

> b) cfg.pieceTheme = URL('static','img/chesspieces/wikipedia/{piece}.png'); 
> //and it fails also
>

Note, URL() is a Python function that works only on the server in the 
web2py environment -- you cannot insert it into a static JS file, which is 
executed entirely within the browser.
 

> The only way I found, so far, to display images is to use the absolute 
> path, see below, which looks like a really bad work around.
>
> cfg.pieceTheme = '
> http://127.0.0.1:8000/tablero/static/img/chesspieces/wikipedia/{piece}.png
> ';
>

If you want to keep the file in /static/img, you can still use a relative 
URL:

cfg.pieceTheme = '../img/chesspieces/wikipedia/{piece}.png 
<http://127.0.0.1:8000/tablero/static/img/chesspieces/wikipedia/%7Bpiece%7D.png>
';

The ../ will traverse from the /js folder up one level to the /static 
folder.

Anthony

-- 
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].
For more options, visit https://groups.google.com/d/optout.

Reply via email to