Created
May 31, 2013 17:14
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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, | |
}); | |
}; | |
}); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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