views:

32

answers:

2

Up to now, I've always hard coded what page template a certain page should use, either based on the URL, or what type of node it is.

What would be really useful is if there was a way to select which tpl file to use, right there in the node edit form. This would allow the user to flick between different page layouts at will.

Does anyone know a good way to approach this problem, or a flat out solution to it?

+2  A: 

ThemeKey will let you load a theme based on a path or other criteria. You can use other methods like utilize preprocesser functions of template.php, and hook it in with hook_form_alter and come up with a way to switch files.

Kevin
Yes, I think I will add a CCK field populated with possible templates, then use a pre processor function to choose the theme template based on that field.
jsims281
A simple approach would be to set a taxonomy vocabulary with the following terms: Theme A, Theme B, Theme C etc. Configure ThemeKey to switch depending on the taxonomy term. And you're done!
Sid NoParrots
Thanks both of you, accept these up-votes with my pleasure.
jsims281
A: 

I ended up adding a new vocabulary for template files (the VID for this is 2 in my case) , and then rolled this into the page preprocessor in my template.php:

function phptemplate_preprocess_page(&$vars) {                                              

  if (count($vars[node]->taxonomy)>0) 
    foreach ($vars[node]->taxonomy as $term) 
      $template = $term->vid == 2 ? $term->name : NULL; 

  if ($template) $vars['template_files'][] = "template-".preg_replace("/[^a-zA-Z0-9s]/", "", strtolower($template));  

}

Now if I have a node in a taxonomy term called: A Green Page! it will look for template-agreenpage.tpl.php as a template file.

jsims281