2

I am building a product site which should use a slightly different page layout for different types of products, depending on what product category they are.

All products are of the same node type. They are categorized based on selected taxonomy terms. The reason I did this instead of creating a different node type for each product category is because some products may exist in multiple categories.

My understanding is that panels relies on the URL structure for determining context. I'm listing all products under ../products/[title] so I dont think that will work. The only way to know the product category is to check the value of a CCK field on that product.

It seems there are many ways to skin a cat in Drupal but I'm unable to figure out what method will allow me to do what Im trying to do.

Any advice/help would be appreciated.

2 Answers 2

3

In D6, if you are displaying a full node page, you can use the preprocess_page() hook to select a different page template based upon that CCK field. For example,

function mythemeormodule_preprocess_page(&$vars) {

  $node=$vars['node'];

  switch ($node->field_i_am_interested_in[0]['value']) {
    case 'something':
    case 'anotherthing':
      $vars['template_file']='page-bytax-' . $node->field_i_am_interested_in[0]['value'];
      break;
  }

}

and then create page-bytax-something.tpl.php page-bytax-anotherthing.tpl.php etc with whatever page layout you want.

If though, you are really talking about how the node itself is laid out in the $content area of the page, you could do the same thing inside preprocess_node() and create node-bytax-FOO.tpl.php templates instead.

Also, depending on what kind of cck field you are looking at, you might need to change up the [0]['value'] part.

If D7, subtle changes apply :)

1
  • I am using D7...
    – Justin
    Mar 2, 2012 at 22:32
2

You can access this information in the definition of the panel variant. If your content has a field, you will find it listed in the Selection Rules tab for the variant. Click on the drop-down list and you will find an item Node Content_Type_Name: your_field_name Selecting this should restrict the content using this variant to the values you specify. Create another variant to cover another set of values.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.