Custom template page-tutorials.tpl.php won't overide page.tpl.php

Inifnitee - May 10, 2008 - 23:48

Hi,
Customized bluemarine theme
Drupal 5.7
Gallery2
phpBB3

I have my page.tpl.php set to display both left and right sidebars and created another page-tutorials.tpl.php without the sidebars but, it still shows them.

Code for page-tutorials.tpl.php:

<table border="0" cellpadding="0" cellspacing="0" id="header">
  <tr>
    <td id="logo">
      <?php if ($logo) { ?><a href="<?php print $base_path ?>" title="<?php print t('Infinitee Exceptional Artists Community') ?>"><img src="<?php print $logo ?>" alt="<?php print t('Infinitee Exceptional Artists Community') ?>" /></a><?php } ?>
      <?php print $search_box ?>
    </td>
  </tr>
  <tr>
    <td colspan="2"><div><?php print $header ?></div></td>
  </tr>
</table>
<div id="footer">
  <?php print $footer_message ?>
</div>
<?php print $closure ?>

Am I missing something or is there another way to create custom page template?

Thanks in advance,
Ralph

This is what I use

future assassin - May 11, 2008 - 04:32

This is what I use http://drupal.org/node/159044

Just create a template.php file and insert the code from the above post. Then upload the template.php file to your default theme directory. I've been using this for quite a while and it works good although it won't work for D6

<?php
function _phptemplate_variables($hook, $vars = array()) {
  switch (
$hook) {
    case
'page':
 
     
// Add page template suggestions based on the aliased path.
      // For instance, if the current page has an alias of about/history/early,
      // we'll have templates of:
      // page_about_history_early.tpl.php
      // page_about_history.tpl.php
      // page_about.tpl.php
      // Whichever is found first is the one that will be used.
     
if (module_exists('path')) {
       
$alias = drupal_get_path_alias($_GET['q']);
        if (
$alias != $_GET['q']) {
         
$suggestions = array();
         
$template_filename = 'page';
          foreach (
explode('/', $alias) as $path_part) {
           
$template_filename = $template_filename . '_' . $path_part;
           
$suggestions[] = $template_filename;
          }
        }
       
$vars['template_files'] = $suggestions;
      }
      break;

    case
'node':
 
     
// Add node template suggestions based on the aliased path.
      // For instance, if the current page has an alias of about/history/early,
      // we'll have templates of:
      // node_about_history_early.tpl.php
      // node_about_history.tpl.php
      // node_about.tpl.php
      // Whichever is found first is the one that will be used.
     
if (module_exists('path')) {
       
$alias = drupal_get_path_alias($_GET['q']);
        if (
$alias != $_GET['q']) {
         
$suggestions = array();
         
$template_filename = 'node';
          foreach (
explode('/', $alias) as $path_part) {
           
$template_filename = $template_filename . '_' . $path_part;
           
$suggestions[] = $template_filename;
          }
        }
       
$vars['template_files'] = $suggestions;
      }
      break;
  }

  return
$vars;
}
?>

$template_filename = $template_filename . '_' . $path_part;

Inifnitee - May 11, 2008 - 23:07

When you use this do you use it as is or do you have to manually add suggestions?

$template_filename = $template_filename . '_' . $path_part;

Like this???

$template_filename = $template_filename . 'my-custom-template.tpl.php' . $path_part;

Infinitee Designs
http://www.infinitee-designs.com/

*

silverwing - May 11, 2008 - 00:51

if you're using aliases (pathauto perhaps) then try this: http://drupal.org/node/139766

If you're using a content type called 'tutorials' you can try adding this to the top of your page.tpl.php
<?php if ($node->type == 'tutorial') { include 'page-tutorial.tpl.php'; return; } ?> (although some say it's not recommended, it does work.)

~silverwing

_____________________________________________
Land of Midnight | MisguidedThoughts | showcaseCMS

You have to tell the theme

WorldFallz - May 11, 2008 - 02:37

You have to tell the theme engine about the template file, try this in the template.php file for your theme:

<?php
function _phptemplate_variables($hook, $vars) {
  switch (
$hook) {
    case
'page':    
     
// Add page template suggestions based on node type.
      // page-nodetype-news.tpl.php
     
if (arg(0) == 'node' && is_numeric(arg(1))) {        
       
$vars['template_files'] = 'page-tutorials';      
      }
    break;
  }
  return
$vars;
}
?>

===
"Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime."
-- Lao Tzu
"God helps those who help themselves." -- Benjamin Franklin
"Search is your best friend." -- Worldfallz

Still not working...

Inifnitee - May 11, 2008 - 12:43

I am new to this stuff so please be specific with explinations. I tried adding 'page-tutorials' as well as 'page-tutorials.tpl.php' and neither seems to work. I am assuming that if I do get this to work that I can add multiple template pages? Something like this...

$template_filename = $template_filename . 'page-tutorials.tpl.php,page-login.tpl.php,page-whatever.tpl.php' . $path_part;

or

$template_filename = $template_filename . 'page-tutorials,page-login,page-whatever' . $path_part;

Which ever is correct.

This is my template.tpl.php: - http://community.infinitee-designs.com/tutorials

<?php
function infinitee_regions() {
  return array(
       
'left' => t('left sidebar'),
       
'right' => t('right sidebar'),
       
'content' => t('content'),
       
'header' => t('header'),
       
'footer' => t('footer'),
               
'header_right' => t('header right'),
       
'frontpage_top' => t('frontpage top'),
       
'frontpage_center' => t('frontpage center'),
       
'frontpage_bottom' => t('frontpage bottom'),
               
'frontpage_latest' => t('frontpage latest'),
               
'frontpage_latest2' => t('frontpage latest2'),
   );
}

?>


<?php
function _phptemplate_variables($hook, $vars = array()) {
  switch (
$hook) {
    case
'page':
 
     
// Add page template suggestions based on the aliased path.
      // For instance, if the current page has an alias of about/history/early,
      // we'll have templates of:
      // page_about_history_early.tpl.php
      // page_about_history.tpl.php
      // page_about.tpl.php
      // Whichever is found first is the one that will be used.
     
if (module_exists('path')) {
       
$alias = drupal_get_path_alias($_GET['q']);
        if (
$alias != $_GET['q']) {
         
$suggestions = array();
         
$template_filename = 'page';
          foreach (
explode('/', $alias) as $path_part) {
           
$template_filename = $template_filename . 'page-tutorials' . $path_part;
           
$suggestions[] = $template_filename;
          }
        }
       
$vars['template_files'] = $suggestions;
      }
      break;

    case
'node':
 
     
// Add node template suggestions based on the aliased path.
      // For instance, if the current page has an alias of about/history/early,
      // we'll have templates of:
      // node_about_history_early.tpl.php
      // node_about_history.tpl.php
      // node_about.tpl.php
      // Whichever is found first is the one that will be used.
     
if (module_exists('path')) {
       
$alias = drupal_get_path_alias($_GET['q']);
        if (
$alias != $_GET['q']) {
         
$suggestions = array();
         
$template_filename = 'node';
          foreach (
explode('/', $alias) as $path_part) {
           
$template_filename = $template_filename . 'page-tutorials' . $path_part;
           
$suggestions[] = $template_filename;
          }
        }
       
$vars['template_files'] = $suggestions;
      }
      break;
  }

  return
$vars;
}

?>


<?php
function _phptemplate_variables($hook, $vars) {
  switch (
$hook) {
    case
'page':   
     
// Add page template suggestions based on node type.
      // page-nodetype-news.tpl.php
     
if (arg(0) == 'node' && is_numeric(arg(1))) {       
       
$vars['template_files'] = 'page-tutorials';     
      }
    break;
  }
  return
$vars;
}

?>

<?php

Here's the page-tutorials.tpl.php:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="<?php print $language ?>" xml:lang="<?php print $language ?>">

<head>
  <title>Tutorials digital &amp; 3D art lessons Maya 3D Studio Max Photoshop</title>
  <?php print $head ?>
  <?php print $styles ?>
  <script type="text/javascript"><?php /* Needed to avoid Flash of Unstyle Content in IE */ ?> </script>
  <script type="text/javascript" src="/js/global.js"></script>
</head>

<body>
<table border="0" cellpadding="0" cellspacing="0" id="header">
  <tr>
    <td id="logo">
      <?php if ($logo) { ?><a href="<?php print $base_path ?>" title="<?php print t('Infinitee Exceptional Artists Community') ?>"><img src="<?php print $logo ?>" alt="<?php print t('Infinitee Exceptional Artists Community') ?>" /></a><?php } ?>
      <?php print $search_box ?>
    </td>
  </tr>
  <tr>
    <td colspan="2"><div><?php print $header ?></div></td>
  </tr>
</table>
<div id="footer">
  <?php print $footer_message ?>
</div>
<?php print $closure ?>
</body>
</html>

And the page.tpl.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="<?php print $language ?>" xml:lang="<?php print $language ?>">

<head>
  <title><?php print $head_title ?></title>
  <?php print $head ?>
  <?php print $styles ?>
  <?php print $scripts ?>
  <script type="text/javascript"><?php /* Needed to avoid Flash of Unstyle Content in IE */ ?> </script>
  <script type="text/javascript" src="/js/global.js"></script>
</head>

<body>
<table border="0" cellpadding="0" cellspacing="0" id="header">
  <tr>
    <td id="logo">
      <?php if ($logo) { ?><a href="<?php print $base_path ?>" title="<?php print t('Home') ?>"><img src="<?php print $logo ?>" alt="<?php print t('Home') ?>" /></a><?php } ?>
      <?php if ($site_name) { ?><h1 class='site-name'><a href="<?php print $base_path ?>" title="<?php print t('Home') ?>"><?php print $site_name ?></a></h1><?php } ?>
      <?php if ($site_slogan) { ?><div class='site-slogan'><?php print $site_slogan ?></div><?php } ?>    </td>
        <td align="right" valign="bottom"><!-- AddThis Button BEGIN -->
      <script type="text/javascript">addthis_pub  = 'Infinitee';</script>
      <a href="http://www.addthis.com/bookmark.php" onmouseover="return addthis_open(this, '', '[URL]', '[TITLE]')" onmouseout="addthis_close()" onclick="return addthis_sendto()"><img src="/images/buttons/AddThis.gif" width="125" height="16" border="0" alt="Bookmark and Share" /></a>
      <script type="text/javascript" src="http://s7.addthis.com/js/152/addthis_widget.js"></script>
        <!-- AddThis Button END -->
</td>
    <td id="menu">
      <?php if (isset($secondary_links)) { ?><?php print theme('links', $secondary_links, array('class' =>'links', 'id' => 'subnavlist')) ?><?php } ?>
      <?php if (isset($primary_links)) { ?><?php print theme('links', $primary_links, array('class' =>'links', 'id' => 'navlist')) ?><?php } ?>
      <?php print $search_box ?>    </td>
  </tr>
  <tr>
    <td colspan="3"><div><?php print $header ?></div></td>
  </tr>
</table>

<table border="0" cellpadding="0" cellspacing="0" id="front-content">
  <tr>
    <td>
    <?php if ($is_front || strstr($_GET['q'], 'admin/block')) : ?>
    <div id="frontpage_top" class="frontpage">
      <?php print $frontpage_top ?>    </div>
    <?php endif; ?>
<?php if ($is_front || strstr($_GET['q'], 'admin/block')) : ?>
    <div id="frontpage_center" class="frontpage">
      <?php print $frontpage_center ?>    </div>
    <?php endif; ?>
<?php if ($is_front || strstr($_GET['q'], 'admin/block')) : ?>
    <div id="frontpage_bottom" class="frontpage">
      <?php print $frontpage_bottom ?>    </div>
    <?php endif; ?>    </td>
  </tr>
  <tr>
    <td>
    <?php if ($is_front || strstr($_GET['q'], 'admin/block')) : ?>
    <div id="frontpage_latest" class="fp-latest">
      <?php print $frontpage_latest ?>    </div>
    <?php endif; ?>
    <?php if ($is_front || strstr($_GET['q'], 'admin/block')) : ?>
    <div id="frontpage_latest2" class="fp-latest">
      <?php print $frontpage_latest2 ?>    </div>
    <?php endif; ?>
    </td>
  </tr>
</table>

<table border="0" cellpadding="0" cellspacing="0" id="content">
  <tr>
  <?php print $breadcrumb ?>
    <?php if ($sidebar_left) { ?><td id="sidebar-left">
      <?php print $sidebar_left ?>
    </td><?php } ?>
    <td valign="top">
      <?php if ($mission) { ?><div id="mission"><?php print $mission ?></div><?php } ?>
      <div id="main">
        <h1 class="title"><?php print $title ?></h1>
        <div class="tabs"><?php print $tabs ?></div>
        <?php print $help ?>
        <?php print $messages ?>
        <?php print $content; ?>
        <?php print $feed_icons; ?>
      </div>
    </td>
    <?php if ($sidebar_right) { ?><td id="sidebar-right">
      <?php print $sidebar_right ?>
    </td><?php } ?>
  </tr>
</table>    

<div id="footer">
  <?php print $footer_message ?>
</div>
<?php print $closure ?>
</body>
</html>

Infinitee Designs
http://www.infinitee-designs.com/

 
 

Drupal is a registered trademark of Dries Buytaert.