I am currently finalizing a site and I need to set up a different template for a portion of the site. This includes different navigation menus and also different blocks.

After doing my research, I discarded the multi site approach as it would require a second setup and did not fit the overall requirements.

I opted to use the Sections module version 5.x-1.2.

So far this module works well for my application. As long as I apply the template to a a number of pages by creating a list of node/xx references in the module visibility options.

Instead I want to take this a little further. I created a new content type called consular_pages. Then instead of applying the template by specifying the node numbers, I want to apply the template to all the pages based on the content type consular_pages.

So for the Sections module visibility options, I selected the php option to create a php filter. However when I try to check for the content type using php, I get an empty or null field for the node type thus my test always returns false.

sample code:

if($node->type =='consular_pages'){
return;
}

How come the test for $node->type returns a null for custom content types?

How can I test the for the content type?

Setup:
Drupal 5.3
Sections module version 5.x-1.2.

Thanks in advance for your input.

Sandro.

PS. I am not sure if this is the right place to ask this question. Please advise.

Comments

hass’s picture

Status: Active » Fixed

I'm not sure if you need the global... Try this one:

if ($node->type == 'consular_pages') {
  return TRUE;
}

Or this:

global $node;
if ($node->type == 'consular_pages') {
  return TRUE;
}
TamboWeb’s picture

Status: Fixed » Postponed (maintainer needs more info)

First thank you for your reply.

I have tried both suggestions; and both evaluated false.

I started to do some testing to see if it is and issue with the sections module or if it is an issue with a broader scope. By the way I am not a PHP expert but I can get my way around with it. Here is what I found:

To test what the if statement was doing I placed the following code withing a "book" content type page in php mode. I figure that if the code resides inside the same content type I should be able to evaluate the if statement and return true, and print it out the the screen.

if ($node->type == 'book') {
  echo '<h2>This is a book page</h2>';
}

or

global $node;
if ($node->type == 'book') {
  echo '<h2>This is a book page</h2>';
}

The result always returns FALSE for both cases.

For my second test I placed both pieces of code within the page.tpl.php file and this piece evaluates true (without the global declaration):

if ($node->type == 'book') {
  echo '<h2>This is a book page</h2>';
}

This leads me to the conclusion that I can't test for node type or content type using the PHP visibility option within the administration as these variables do not pass along. They can only be accessed from within the theme template files and not from the content administration.

Is there a way to pass these values over the content administration side so that I can apply the proper content filtering ?

I know this type of filtering can be applied to the template.php and theme files. However, I would like to apply the filtering at the administration side because this will allow greater control how the themes and blocks are assigned to each content type.

your thoughts are most welcome.

hass’s picture

Status: Postponed (maintainer needs more info) » Fixed

Check this page out http://drupal.org/node/60317. It have many examples...

TamboWeb’s picture

Hass,

Thank you for taking the time to respond to my questions and for providing some guidance.

I found a piece of code that did the trick.

$match = FALSE;
if (arg(0) == 'node' && is_numeric(arg(1))) {
  $nid = arg(1);
  $node = node_load(array('nid' => $nid));
  $type = $node->type;
  if ($type == 'consul_page') {
    $match = TRUE;
  }
}
return $match;

I got the idea from this node: http://drupal.org/node/64135

Hope this helps others as well.

With this setup I can manage one site with one section that is completely independent in regards to theme, blocks and menus than the rest of the site without having to set up multiple sites. The benefit here is that the administrators can simply create content using one of the pre-defined content types and automatically the theme gets applied to it. Another benefit is that there is a single administrator for the whole site.

Please note that the code above may still need some refinement as i have not fully tested it.

Thanks again.

Sandro.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

spark71’s picture

code :

if (arg(0) == 'node' && is_numeric(arg(1))) {
  $nid = intval(arg(1));
  $node = node_load(array('nid' => $nid));
  $type = $node->type;
  return in_array($type, array("webform"));
}