Skip to content

Instantly share code, notes, and snippets.

@mrchrisadams
Created May 31, 2013 17:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrchrisadams/5686428 to your computer and use it in GitHub Desktop.
Save mrchrisadams/5686428 to your computer and use it in GitHub Desktop.
Pattern for getting ands setting variables across environments with Drupal and PHP. Trying to reconcile with a twelve factor approach, and Drupal's insistence on storing things in a database at any given opportunity.
## vars specific to the environment:
drush vset('facebook_app_id', get_env('facebook_app_id'))
## fetching changes from code
drush fu all
## fetching changes from code
drush cc all
// lets say I want to call facebook asynchronously now,
// I'd pull like so:
$.getScript('//connect.facebook.net/en_UK/all.js', function() {
window.fbAsyncInit = function() {
FB.init({
appId: Drupal.myModule.facebook_app_id,
});
};
});
<?php
$handy_value = variable_get('my_form_element')
// set our value first that the facebook code uses
drupal_add_js(array('myModule' => array('facebook_app_id' => $handy_value)), 'setting');
// then include the facebook code, makign
drupal_add_js(drupal_get_path('module', 'myModule') . '/facebook.js', );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment