Drupal 7 - What is the variable in template.php that dictates which page template is used? -


ok, here's deal: constructing drupal website has several different sections. each section view displays content type. (each section has it's own content type) example, have view points ?q=blog displays content type blog.

all sections little different each other. not 'website-within-a-website' different different enough can't use same template file , each modified css. each section needs it's own page.tpl.php.

unfortunately, afaik drupal theme's .info files can either assign 1 page.tpl.php entire theme or assign page-node-####.tpl.php each node. there going lots of content on website setting drupal make new identical page-node-####.tpl.php every created node unmanagable fast.

to solve problem, going use pathauto create alias each content type. example, nodes of content type blog given alias ?q=blog/[post title]. modify template.php use page-blog.tpl.php page who's alias starts word 'blog'.

other people have tried doing sort of thing , have created functions such 1 described. unfortunately, ones have seen drupal 6 or below. have tried modifying existing ones no success. far, though, think on right track:

function basic_preprocess_page(&$vars, $hook) {     ...      if( module_exists('path') ) {         $alias = drupal_get_path_alias( $_get['q'] );         $site_section = "blog";         if( strpos( $alias, $site_section ) === 0 ) {             $variable_that_tells_the_page_what_template_to_use = "/path/to/page-blog.php";         }     } } 

i cannot find $variable_that_tells_the_page_what_template_to_use know is?

maybe site structured badly. if knows how restructure site can more make theme seperate sections please share how!

thanks million! (c:

edit: perhaps need use template suggestions instead. know function or variable use set this?

they changed name of array key in d7 , haven't seen documented anywhere. figured out after bit of debugging. can override theme template in template.php hook_preprocess_page() so:

function mytheme_preprocess_page(&$vars) { global $node;  if ($node->type == 'blog') {      $vars['theme_hook_suggestions'] = array('my__blog_template'); // use my--blog-template.tpl.php, note '-' = '_' } elseif ($node->type == 'articles') {     $vars['theme_hook_suggestions'] = array('article__node_template'); // use article--node-template.tpl.php } } 

oh , don't forget flush drupal caches after making changes template.php.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -