Skip to content

Instantly share code, notes, and snippets.

@heyMP
Last active December 28, 2015 22:19
Show Gist options
  • Save heyMP/7570414 to your computer and use it in GitHub Desktop.
Save heyMP/7570414 to your computer and use it in GitHub Desktop.
Two methods of working with preprocess variables
// Altering the render array
function YOUR_THEME_preprocess_field(&$variables) {
//Giveaway node: field giveaway value
//change to dollar format
if ($variables['element']['#field_name'] == 'field_giveaway_value') {
$dollar_value = money_format('$%i', $variables['element']['#items'][0]['safe_value']) . "\n";
$variables['items'][0]['#markup'] = $dollar_value;
}
}
// Adding new variables that we be sent to the template file
function YOUR_THEME_preprocess_node(&$variables) {
if ($variables['type'] == 'giveaway') {
$node = $variables['node'];
//Format Giveaway end dates
$timestamp = strtotime($node->field_giveaway_duration['und'][0]['value2']);
$variables['duration_endyear'] = format_date($timestamp, 'custom', 'Y');
$variables['duration_endmonth'] = format_date($timestamp, 'custom', 'n');
$variables['duration_endday'] = format_date($timestamp, 'custom', 'j');
}
}
@heyMP
Copy link
Author

heyMP commented Nov 20, 2013

These functions reside in your themes template.php file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment