Posts Tagged ‘Theming’

Theming multiple value CCK fields in Views

Colin Calnan | Monday, June 22nd, 2009

I’m working on a site right now that has a Publications content type, which in turn has a multiple value CCK text field for Author. If more than one author was input I needed them to display as a comma separated list in a view. How do you go about modifying this? My first stop was the theming info link in Views, and that helped me narrow it down to a template file to use, views-view-field.tpl.php(). But that file didn’t allow me to modify the individual fields without getting a whole load of other HTML in the bargain.

< ?php
// $Id: views-view-field.tpl.php,v 1.1 2008/05/16 22:22:32 merlinofchaos Exp $
 /**
  * This template is used to print a single field in a view. It is not
  * actually used in default Views, as this is registered as a theme
  * function which has better performance. For single overrides, the
  * template is perfectly okay.
  *
  * Variables available:
  * - $view: The view object
  * - $field: The field handler object that can process the input
  * - $row: The raw SQL result that can be used
  * - $output: The processed output that will normally be used.
  *
  * When fetching output from the $row, this construct should be used:
  * $data = $row->{$field->field_alias}
  *
  * The above will guarantee that you'll always get the correct data,
  * regardless of any changes in the aliasing that might happen if
  * the view is modified.
  */
?>
< ?php print $output; ?>

Using the brilliant “Theme developer” extension of the Devel module I was able to pin point the theme function – theme_content_view_multiple_field that would allow me to modify the actual value of the field without the wrapper div’s etc (I’m not getting into the views divitis argument.

Here’s a quick snippet of code to place in your template.php file of your theme to allow you to modify multiple value fields:

function custom_theme_content_view_multiple_field($items, $field, $values) {
  $output = '';
  switch($field['field_name']) {
    // If this is the author field then we need to comma separate the authors
    case 'field_author':
      $output .= '<div class="field-item">'. implode(', ', $items) .'</div>';
      break;
 
    default:
      foreach ($items as $item) {
        if (!empty($item) || $item == '0') {
	  $output .= '<div class="field-item">'. $item .'</div>';
	}
      }
      break;
  }
  return $output;
}

I used a switch statement because I have a lot of other multiple fields that need to be themed in different ways and it’s nicer than a whole load of if statements. Also switch provides a default state if a condition isn’t met.

Our Theme Toolkit

Colin Calnan | Thursday, March 5th, 2009

So we (Christopher and I) are at DrupalCon, and one of the questions to the floor at The Themer’s Toolkit was “What theme toolkit do you use?”. I thought I’d give a quick overview of our toolkit:

Theme

We’ve been using a custom three column layout that Christopher developed way back when, but recently we’ve been tweaking it considerably, to include new features such as video support, stylesheet switching, custom search form and IE support. It’s now similar to Zen in many ways and provides context/content specific classes and ids for ease of styling. We have plans for the future to create a more flexible theme based on CSS frameworks.

Install Profile

We have our own custom install profile that configures things like TinyMCE and CCK settings as well as setting up an admin user etc.

Coding tools

We are primarily a Mac/Adobe shop, so we have been using Dreamweaver up to now, however we sometimes use TextMate for new projects or projects that don’t require a check-in/check-out capability. With the prospect of version control tools coming in the future we will be reviewing and reassessing. I know there are some hardcode VIM and Emacs users out there, we promise we’ll consider both :)

Version Control

Historically we have been a single developer shop with no need for a version control system as most sites were developed and then rolled out without need to many updates. However with the addition of more custom modules, working on much larger sites and the expansion of our team we now feel it necessary to implement some sort of version control system. Having seen some of these in action at DrupalCon, we will be working to have something running in a few months.

Modules

We use the standard modules such as CCK, Views etc. but also have the following custom modules:

Mobile Detection Module

I’ve recently finished a rough beta version of a mobile redirection module which uses this code to detect the user agent and then redirects to a specified URL. In most case we use a sub-domain folder like /sites/m.example.com and configure the settings.php to use a separate theme. We’ll release this at some point also when it meets drupal’s code and module development standards, not that it doesn’t already but we need to make it less site specific.

Block Class extension

I wrote an extension to the block class module that allows the user to choose from a specified list of block class options, rather than typing one in.

Node title length

In some cases, to stop the design from breaking, we need to ensure that the node title lengths are restricted to a certain maximum. This module allows you to choose the content types to apply the restriction to and does the necessary validation.

CSS Image Replacement

Chris wrote a totally awesome tool that we then roughly ported to a module that uses CSS to do image replacement. For now that’s all I can say, we’ll be working on releasing it in the wild at some point but it rocks and relies on GD libraries and CSS definitions to create images to replace text.

Advanced Menus

Chris built this module to allow us to place any of the available drupal menus in a block and position this anywhere on the site.

We’re constantly working to improve on our workflow, and having recently become a 2 person development team, soon to be 3, we are conscious that improvements need to be made in preparation for future growth. If you have any tips of suggestions for a team the size of ours I’d love to hear them.

 


t. 604.684.2498 | f. 604.721.4007 | e. turningheads [at] raisedeyebrow.com