Last active
December 28, 2015 22:19
-
-
Save heyMP/7570414 to your computer and use it in GitHub Desktop.
Two methods of working with preprocess variables
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
// 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'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
These functions reside in your themes template.php file.