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 / setget_cookie
Created November 19, 2012 15:38
Set and get cookie
@jeremycaldwell
jeremycaldwell / window.height.resize
Created August 30, 2013 22:31
Set div to be full height of window and resize when browser window height changes.
$(window).resize(function(){
var windowHeight = jQuery(window).height();
$("#header").height((windowHeight) + 'px');
});
@jeremycaldwell
jeremycaldwell / template.php
Created August 30, 2013 22:38
Drupal 7 - Breadcrumbs
/**
* Implements hook_breadcrumb
*/
function THEMENAME_breadcrumb($variables) {
$breadcrumb = $variables['breadcrumb'];
$crumbs = '<div class="breadcrumb"><div class="wrapper"><ul>';
if (!empty($breadcrumb)) {
// Provide a navigational heading to give context for breadcrumb links to
// screen-reader users. Make the heading invisible with .element-invisible.
@jeremycaldwell
jeremycaldwell / template.php
Last active December 22, 2015 01:18
Drupal 7 - Node preprocess
/**
* Override or insert variables into the node templates.
*
* @param $vars
* An array of variables to pass to the theme template.
*/
function THEMENAME_preprocess_node(&$vars) {
$node = $vars['node'];
@jeremycaldwell
jeremycaldwell / template.php
Created August 30, 2013 22:47
Drupal 7 - Form alter
/**
* Implements hook_form_FORM_ID_alter().
*/
function THEMENAME_form_alter(&$form, &$form_state, $form_id) {
switch ($form_id) {
// Remove descriptions
case 'user_login':
unset($form['name']['#description']);
unset($form['pass']['#description']);
@jeremycaldwell
jeremycaldwell / node.tpl.php
Last active December 22, 2015 01:18
Drupal - l() function with HTML and class.
<?php print l('<span>' . t('MY TITLE') . '</span>', 'myurl', array('html' => TRUE, 'title' => t('SOME TITLE'), 'attributes' => array('class' => 'myclass'))); ?>
@jeremycaldwell
jeremycaldwell / views.php
Created August 30, 2013 22:50
Drupal - Views: Fields
<?php
print print_r(array_keys($fields), 1);
// Or if you have the developer module installed
dsm(array_keys($fields));
?>
<?php if (isset($fields['field_employee_portrait']->content)): ?>
<div class="author-photo">
<?php print $fields['field_employee_portrait']->content; ?>
@jeremycaldwell
jeremycaldwell / template.php
Created August 30, 2013 22:51
Drupal 7 - Search block alter
/**
* Implements hook_form_FORM_ID_alter().
*/
function THEMENAME_form_alter(&$form, &$form_state, $form_id) {
switch ($form_id) {
// Search block form
case 'search_block_form':
@jeremycaldwell
jeremycaldwell / node.tpl.php
Created August 30, 2013 22:52
Drupal 7 - Role
<?php
global $user;
$approved_roles = array('administrator');
if (is_array($user->roles)) {
if (count(array_intersect($user->roles, $approved_roles)) > 0) {
print 'You are admin';
} else {
print 'You are NOT admin';
}
}
@jeremycaldwell
jeremycaldwell / template.php
Created August 30, 2013 22:52
Drupal 7 - Change page title based on path.
function THEMENAME_preprocess_page(&$vars) {
if (arg(0) == 'user' && arg(1) == 'login') {
drupal_set_title(t('Login'));
}
if (arg(0) == 'user') {
drupal_set_title(t('Login'));
}
if (arg(0) == 'user' && arg(1) == 'password') {