Fix for use a CCK field to switch node templates

  1.   // ----------------------------- node templates
  2.   // $vars['template_files'] holds an array of template suggestions,
  3.   // from most generic to most specific.
  4.   // Here we add our own suggestions for some node types.
  5.   // NOTE: extra per-node CSS is addded in the page hook for stylesheet ordering reasons.
  6.  
  7.   // Some node types have 'sub-templates' -- the template they get
  8.   // depends on the value of a CCK field.
  9.   // - project node type
  10.   if($vars['node']->type == 'project') {
  11.     $project_template = $vars['node']->field_project_template[0]['value'];
  12.     if (!$project_template) {
  13.       $project_template = 'basic';
  14.     }
  15.     $vars['template_files'][] = 'node-project-'. $project_template;
  16.   }
  17.   // - event node type
  18.   if($vars['node']->type == 'event') {
  19.     $event_template = $vars['node']->field_event_template[0]['value'];
  20.     if (!$event_template) {
  21.       $event_template = 'basic';
  22.     }
  23.     $vars['template_files'][] = 'node-event-'. $event_template;

Submit Fix

Any tags you'd like to associate with your code, delimitered by commas (example: Views, CCK, Module, etc).
Select the syntax highlighting mode to use.