General developer forum

Fetch (or pass) a Moodle config value to theme JS file

 
Picture of Rob Emenecker
Fetch (or pass) a Moodle config value to theme JS file
 

Hi all,

I am working on extending a custom Moodle theme. The existing theme loads a number of JavaScript files contained in the theme's javascript directory via the $THEME global in the theme's config.php file:

$THEME->javascripts = array(
    'javascriptfile1', 
    'javascriptfile2',
    ...
);
$THEME->javascripts_footer = array(
    ...
);

Now, in javascriptfile1 I need the value of...

get_config('theme_THEMENAME','someconfigval');

I am trying to avoid full-scale refactoring of the JS to YUI, but the only way I currently know to pass a value to JS is via:

$PAGE->requires->js_init_call(...). 

Anyone know of a practical way to do what I need? I've been searching and thus far have not had any luck.

---Rob


 
Average of ratings: -
Gareth J Barnard
Re: Fetch (or pass) a Moodle config value to theme JS file
 
Average of ratings: -
Picture of Rob Emenecker
Re: Fetch (or pass) a Moodle config value to theme JS file
 

Thanks, Gareth!

I was inching my way toward AMD modules as the way to go. I will take a look at the theme file links your provided. 

---Rob

 
Average of ratings: -