Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Path in external JS
#1
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
Reply
#2
Maybe this?

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

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

Romain
Reply
#4
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',
Reply
#5
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
Reply
#6
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
}; 
Reply
#7
(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.
Reply
#8
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.
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#9
Sorry for the late reply.

The solution from Kolyok works great !

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

Romain
Reply




Users browsing this thread: 2 Guest(s)