Skip to content

Instantly share code, notes, and snippets.

@rlnorthcutt
Last active August 27, 2015 05:36
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 rlnorthcutt/71155b292c6448bd7db1 to your computer and use it in GitHub Desktop.
Save rlnorthcutt/71155b292c6448bd7db1 to your computer and use it in GitHub Desktop.
<!-- No PHP in the template, even though it has the PHP extension on the file. -->
<div class={{ classes }} pod">
<div class="pod--inner">
<h3>{{ title }}</h3>
{{ image }}
<p>{{ promo }}</p>
{{ link }}
<p><small>{{ terms }}</small></p>
</div>
</div>
/**
* This is all angular. Consider this a total guess as to the angular code itself,
* but the process of grabbing the data from Drupal is straightforward.
*/
var app = angular.module('myapp', [])
.controller('promoBlock', function($scope, $http, $log) {
$variables = Drupal.settings.promoBlock.variables;
// Now we can grab the values out of the object as necessary and do what we want
$title = $variables['title'];
// ...
// We can also call any external services, modify the values, add extra info, etc.
});
<?php
/**
* Preprocess function for fieldable-panels-pane.tpl.php
* We are only using this to grab the information from the promo block widget
* and pass it to javascript.
*/
function sprint_preprocess_fieldable_panels_pane(&$variables = array()) {
if ($variables->type == 'promo_block') {
// This is the bridge between PHP and JS
drupal_add_js(array("promoBlock" => $variables), 'setting');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment