Hi

I'm not a dev , and when i found a code for template.php like i want, i believed it will be easy...but not.Here is my source ( http://drupal.org/node/723544#comment-3997982 ) ; but it doesnt work for me after adapt it; this is my actual code :

/*Permet d'attribuer un template de node différent selon terme de taxo et type de contenu
 * - NE PAS OUBLIER DE CHANGER LE NOM DU THEME !!!___
http://drupal.org/node/723544 */
function cyrano_ce_preprocess_node(&$vars) {
 $node = $vars['node'];
  if($node->type == 'page_fiche_formation') {
    // Check if custom layout defined in taxonomy
    if(!empty($node->taxonomy) && $node->taxonomy[1]->vid == 1) {
      $vars['template_files'][] = 'node-' . $node->taxonomy[1]->name;
    }
  }
}

i've tried to change the node.tpl name between node-term-name.tpl or node-term_name.tpl but no change...i'dont know which use between the label of the term or the machine name of the term ( display when i fly over the term name whith the mouse in "admin/content/taxonomy/1".
i dont know why it doesnt work, perhaps on the code about term...no $terms is defined i think...if dev come around, i'll be very happy

here what i would to do : " applying a node.tpl custom template to a node which get the right content type and is tagged by the right taxonomy term; after that the taxonomy term is used to named the node.tpl custom file..."

thanks and hope

Comments

aiphes’s picture

so i try to go ahead , it seem my term isnt well testes or recognized by the function :


function cyrano_ce_preprocess_node(&$vars) {
$node = $vars['node'];
   // on verifie l'appartenance au type de contenu
   if($node->type == 'page_fiche_formation') {
       if ( ! empty($node->taxonomy)  ) {
// Récupération du 1er element du tableau
           $term = array_shift($node->taxonomy);
    // verifie si le terme appartient bien au vocabulaire vid=1
           if ( $term->vid == 1 ) {
              $tplfile = 'node-' . $term->name. 'tpl.php';
              $vars['template_files'][] = $tplfile;
           drupal_set_message('Term name : '.$term->name,'status');
           drupal_set_message('Template file : '.$tplfile,'status');
          }
      }

    }
     drupal_set_message('Term name hors boucle: '.$term->name,'status');
     drupal_set_message('Template file hors boucle: '.$tplfile,'status');
}

if a dev could help..

Dev Server Shared Hosting
8 websites powered by drupal 6,8 & 9 - Hosted by Always Data

aiphes’s picture

ok the code is working, just to take care of term display module which doesnt allow to take the term name value...now i would to clean up the term name to a "machine name" for template name.

Dev Server Shared Hosting
8 websites powered by drupal 6,8 & 9 - Hosted by Always Data

hazarvolga’s picture

ı try this code but dosent work. just change node type . ı have one term= "category" terms=" a"/"b"/"c"
can you help me . sorry for my poor english. thanks

function simpleclean_preprocess_node(&$vars) {
$node = $vars['node'];
// on verifie l'appartenance au type de contenu
if($node->type == 'product') {
if ( ! empty($node->taxonomy) ) {
// Récupération du 1er element du tableau
$term = array_shift($node->taxonomy);
// verifie si le terme appartient bien au vocabulaire vid=1
if ( $term->vid == 1 ) {
$tplfile = 'node-' . $term->name. 'tpl.php';
$vars['template_files'][] = $tplfile;
drupal_set_message('Term name : '.$term->name,'status');
drupal_set_message('Template file : '.$tplfile,'status');
}
}

}
drupal_set_message('Term name hors boucle: '.$term->name,'status');
drupal_set_message('Template file hors boucle: '.$tplfile,'status');
}
}