Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Experimental project
This is a sandbox project, which contains experimental code for developer use only.
This module exposes all variables defined with Variable API to JavaScript API.
Usage
- Checkout and enable module
- In hook_variable_info() define your variables to be exportable to JavaScript
- Access your variables from Javascript with code like:
Drupal.settings.variable_js.variableName
(note that changes will not persist).
Example handler
function mymodule_variable_info() {
$variables = array();
$variables['mymodule_info'] = array(
'title' => t('Info text'),
'description' => t('Sample variable with information'),
'type' => 'string',
'token' => TRUE,
'multidomain' => TRUE,
'js' => TRUE,
);
return $variables;
}
Example JavaScript usage
function($) {
Drupal.behaviors.mymodule_test = {
attach : function(context) {
alert(Drupal.settings.variable_js.mymodule_info);
}
}
})(jQuery);
Note: examples were not tested on animals ;-).
Dependencies
Requires Variable.
To do
Some ideas for improvement:
- Allow exporting to JS of variables from GUI (add a checkbox in variable GUI that enables any variable to be exportable to JS)
- Allow saving of variable modifications made in JavaScript (some AJAX magic will be required)
Currently I don't have time / motivation / need for these, but if you find any of them interesting - let me know / create a feature request issue.
Project information
- Minimally maintained
Maintainers monitor issues, but fast responses are not guaranteed. - Maintenance fixes only
Considered feature-complete by its maintainers. - Created by lklimek on , updated