URL based templates

urrestieta - March 27, 2008 - 19:12

Hi

I need to use different templates for different areas of my website. I read the explanation on how to use URL based templates but my situation is more particular than that.

I have a set of nodes under the following URL

www.myurl.com/es/artistas/*

for example es/artistas/jon , es/artistas/peter or es/artistas/mary
and I would like all of them to use the same template. I tried to create a template calle artistas.tpl.php but of course it doesnt work.

At the same time because of using i18n i am getting the "es" and "en" at the beggining of the URL. Of course once the english version is running there will be nodes under

www.myurl.com/en/artistas/*

So I need
www.myurl.com/en/artistas/jon
and
www.myurl.com/es/artistas/mary

to use the same template. Again I tried "es-artistas.tpl.php" with no luck.

So basically I need a way to pay attention to the second item ("artistas" in this case) of the URL when choosing the template.

I dont really know where to start from, I dont know Drupal well enough for solving this on my own from scratch. Any hints would be apreciated. Thanks!!

enrike

Taxonomy Theme?

rjoy - March 27, 2008 - 21:32

Have you looked at the Taxonomy Theme (http://drupal.org/project/taxonomy_theme) module? It sounds like this might fit the bill...

solved but i am having a look at your suggestion

urrestieta - March 28, 2008 - 08:12

To my absolute surprise i was able to solve my problem modifying PHP snipset I found. Looks like i am getting better at drupal and php ;)

But i am having a look at your suggestion, sounds like that might be cleaner solution. Thanks!

anyway just in case anyone is interested this is the code I used. It goes into template.php

function _phptemplate_variables($hook, $vars = array()) {
  switch ($hook) {
    case 'page':
      // Add node template suggestions based on the aliased path.
      // I am interested on the second item of the URL , so this is how it works
      // es/artistas/inaki and en/artistas/pedro
      // corresponds to page-artistas.tpl.php
      if (module_exists('path')) {
        $alias = drupal_get_path_alias($_GET['q']);
        if ($alias != $_GET['q']) {
          $suggestions = array();
          $all = explode('/', $alias);
          $suggestions[] = 'page-'.$all[1]; // change this to your needs
        }
        $vars['template_files'] = $suggestions;
      }
      break;
  }

return $vars;
}

 
 

Drupal is a registered trademark of Dries Buytaert.