GetSimple Support Forum
Path in external JS - Printable Version

+- GetSimple Support Forum (http://get-simple.info/forums)
+-- Forum: GetSimple (http://get-simple.info/forums/forumdisplay.php?fid=3)
+--- Forum: General Questions and Problems (http://get-simple.info/forums/forumdisplay.php?fid=16)
+--- Thread: Path in external JS (/showthread.php?tid=5078)



Path in external JS - rpetges - 2013-08-18

Hi,

My HTML5 theme is based on the SkelJS frontend framework and basic configuration is done in an external Javascript file.

Example for static HTML:

window._skel_config = {
preset: 'standard',
prefix: 'css/style',
resetCSS: true
};

Within GetSimpleCMS, I need however to put the full path from the root of the hosting space for the prefix variable :

window._skel_config = {
preset: 'standard',
prefix: '/cms/theme/mytheme/css/style', ( or http://www.mydomain.com/cms/theme/mytheme/css/style )
resetCSS: true
};

I don't understand why I do need to put the complete path when code is served by GetSimple.

I would prefer relative paths, but all my tests so far failed.

Many thanks for your help,
Romain


RE: Path variable in external JS - Carlos - 2013-08-18

Maybe this?

prefix: '<?php get_theme_url(); ?>/css/style',


RE: Path in external JS - rpetges - 2013-08-18

Thanks for the suggestion.

Javascript files are read on the client side and PHP code is server based ... this won't work.

Romain


RE: Path in external JS - Carlos - 2013-08-18

Where is that js file located?

If it's in another theme subfolder (e.g. /cms/theme/mytheme/js/), could this work?

prefix: '../css/style',


RE: Path in external JS - rpetges - 2013-08-19

The filesystem structure is the following one :

/cms/theme/mytheme/js <-- config.js is located here
/cms/theme/mytheme/css <--- styles inside this folder cannot be loaded

I also tried the ../ option and it does not work.

Romain


RE: Path in external JS - Kolyok - 2013-08-19

Maybe not the best solution but you could try to declare a javascript variable just before loading the config.js and then pass that variable to prefix.
PHP Code:
#Set variable before loading the config.js (inside your template file)

var ThemeStyleAbsPath '<?php get_theme_url(); ?>';

#Pass variable to config.js

window._skel_config = {
    
preset'standard',
    
prefixThemeStyleAbsPath '/css/style',
    
resetCSStrue
}; 



RE: Path in external JS - Carlos - 2013-08-19

(2013-08-19, 14:03:41)rpetges Wrote: The filesystem structure is the following one :

/cms/theme/mytheme/js <-- config.js is located here
/cms/theme/mytheme/css <--- styles inside this folder cannot be loaded

I also tried the ../ option and it does not work.

If Kolyok's solution doesn't work, you could put your styles and config.js file in the same folder (js or cs, or a new one, e.g. assets), and then just use:

prefix: 'style',

[edit] fixed typo.


RE: Path in external JS - shawn_a - 2013-08-19

Are you using relative to your source document, not your js file ?
Relative urls should work.

Like kolyok said, you have to define inline somewhere before your config inits.


RE: Path in external JS - rpetges - 2013-08-23

Sorry for the late reply.

The solution from Kolyok works great !

Many thanks for your help, it's much appreciated.

Romain