Skip to content

Instantly share code, notes, and snippets.

View jeremycaldwell's full-sized avatar
💭
Currently available for hire.

Jeremy Caldwell jeremycaldwell

💭
Currently available for hire.
View GitHub Profile
@jeremycaldwell
jeremycaldwell / node.tpl.php
Created August 30, 2013 22:53
Drupal 7 - User picture
<?php if ($picture): ?>
<?php
$user = user_load($user->uid);
print theme_image_style (
array (
'style_name' => 'user-photo',
'path' => $user->picture->uri,
'attributes' => array ('class' => 'user-photo'),
'width' => NULL,
'height' => NULL,
@jeremycaldwell
jeremycaldwell / template_clean.php
Last active December 22, 2015 01:18
Drupal 7 - Image
<?php
$path = $vars['field_company'][0]['entity']->field_company_logo_medium['und'][0]['uri'];
$alt = $vars['field_company'][0]['entity']->title;
$title = t('View case study');
$logo = '<img src="' . file_create_url($path) . '" title="' . $title . '" alt="' . $alt . '"/>';
// Logo
$vars['content']['logo'] = array(
'#markup' => l($logo, 'node/' . $node->nid, array('html' => TRUE)),
@jeremycaldwell
jeremycaldwell / script.js
Created August 30, 2013 22:54
Drupal 7 - Javascript
/**
* @file
* A JavaScript file for the theme.
*
* In order for this JavaScript to be loaded on pages, see the instructions in
* the README.txt next to this file.
*/
// JavaScript should be made compatible with libraries other than jQuery by
// wrapping it with an "anonymous closure". See:
@jeremycaldwell
jeremycaldwell / node-6.tpl.php
Last active January 20, 2017 05:37
Drupal 6/7 - Embed block in node
<?php
$block = module_invoke('views', 'block' , 'view', 'fanvision_news-block_1');
print $block['content'];
?>
@jeremycaldwell
jeremycaldwell / template.php
Created August 30, 2013 22:56
Drupal 7 - Add Javascript for specific paths
/**
* Load specific Javscript on specific pages based on node id.
*
* @param $vars
* @param $hook
*/
function THEMENAME_preprocess(&$vars, $hook) {
$node = menu_get_object('node');
// Disable race
@jeremycaldwell
jeremycaldwell / template.php
Created August 30, 2013 22:57
Drupal 7 - Pre function to print out variables
function print_r_html ($arr) {
?><pre><?
print_r($arr);
?></pre><?
}
function THEMENAME_form_alter(&$form, &$form_state, $form_id) {
print_r_html($form);
}
@jeremycaldwell
jeremycaldwell / template.php
Created August 30, 2013 22:57
Drupal 7 - Page alter
function THEMENAME_preprocess_page(&$vars) {
// Change site name based on language
global $language;
$userlanguage = $language->language;
switch ($userlanguage) {
case 'en':
case 'uk':
case 'ie':
$vars['site_name'] = t('Partner Marketing Materials');
@jeremycaldwell
jeremycaldwell / template.php
Created August 30, 2013 22:58
Drupal 7 - Add CSS for specific paths
function THEMENAME_preprocess_page(&$vars) {
// Add "addcourse.css" to Add Course page only
if(strstr($_SERVER['REQUEST_URI'], "admin/commerce/products/$path_alias")) {
drupal_add_css(
path_to_theme() . '/css/addcourse.css',
array(
'group' => CSS_THEME,
)
);
@jeremycaldwell
jeremycaldwell / node.tpl.php
Last active January 30, 2018 19:51
Drupal - Node variables
<?php
// Set up some variables
$photo = $node->field_profile_photo['und']['0']['view'];
$recommend = $node->field_profile_recommend['und']['0']['value'];
$body = $node->content['und']['body']['#value'];
?>
<?php if ($photo): ?>
<div class="profile-photo profile-field">
<h3><?php print t('Photo'); ?>:</h3>
@jeremycaldwell
jeremycaldwell / EmToPX.sass
Created September 5, 2013 19:57
Convert "px" to "em".
// Convert "px" to "em"
@function em($target, $context: $base-font-size) {
@if $target == 0 { @return 0 }
@return $target / $context + 0em;
}