GetSimple Support Forum

Full Version: Path in external JS
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
Maybe this?

prefix: '<?php get_theme_url(); ?>/css/style',
Thanks for the suggestion.

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

Romain
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',
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
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
}; 
(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.
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.
Sorry for the late reply.

The solution from Kolyok works great !

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

Romain