Hi,

i'm new in Drupal (ex postnuke user) and i would like to know if it's possible to
apply different html templates for differents taxonomy or different module or different block.

If we can do it, where can I find documentation about it?

I look on the forum put I found a lot of un-awnsered answers

http://drupal.org/node/view/6639
http://drupal.org/node/view/7039
http://drupal.org/node/view/4608

I have this website, which 3 different layout (start page, first level page (topic) and second level page (subtopic)

Thanks,

Roseline Paquin
roseline43@hotmail.com

Comments

matt westgate’s picture

This can be done, although you'd need to be comfortable with some PHP code to do it. Here's the approach I would take off the top of my head.

In most cases, the templating happens in the current themes' page hook. So that is the place to add template switching logic. For example if your site was divided up into sections using taxonomies, you could switch templates based on the current pages' taxonomy term. This method would change the entire site design. It's much easier if you just want to make your nodes look differently.

Templates for blocks are easy as well. Viewing the source code of any Drupal page with blocks will reveal that each block is assigned an unique ID that can be controlled with CSS.

phani’s picture

i was looking for a way to switch sidebars on and off depending on node-type in the chameleon-theme (plain php). using phptemplate-themes that was easy, since $node->type is available there. i couldn't find a way to get at the node-type from within the function chameleon_page() in the chameleon.theme - file, though - obviously because it receives $content as parameter, not the $node.

being new to drupal i'm wondering if the solution i came up with has any serious drawbacks, i.e., if i shouldn't be doing this for some reason i'm not aware of:

i declared $node_type_phani as a global variable from within the function chameleon_node(), which receives $node as parameter, assigned the value $node->type, and now i can get at the node-type from within the _page-function. this works fine, but i'm wondering if this is really necessary, or if the node-type isn't already accessible from the _page() - function in some other way ?

phani.

erikhopp’s picture

hi. ok, i figured out how to add to the node type to the class for styling nodes in xtemplate.

first, (in current CVS) you need to add a line in function "xtemplate_node" - roughly line #68 in xtemplate.theme (see arrow):

so that it now looks like this:

<code>  $xtemplate->template->assign(array(
	
        "submitted" => t("Submitted by %a on %b.",
                      array("%a" => format_name($node),
                            "%b" => format_date($node->created))),
        "link"      => url("node/$node->nid"),
        "title"     => $node->title,
        "author"    => format_name($node),
        "date"      => format_date($node->created),
        "sticky"    => ($main && $node->sticky) ? 'sticky' : '',
-->	"node_type"      => $node->type,
        "content"   => ($main && $node->teaser) ? $node->teaser : $node->body));

then, add lines (at roughly line #70 and #86) in xtemplate.xtpl so that the whole node markup looks like this (see arrows):

<code><!-- BEGIN: node -->

  <div class="node {sticky}">
--> <div class="{node_type}">
    <!-- BEGIN: picture -->
    <div class="picture">{picture}</div>
    <!-- END: picture -->
    <!-- BEGIN: title -->
    <h2 class="title"><a href="{link}">{title}</a></h2>
    <!-- END: title -->
    <span class="submitted">{submitted}</span>
    <!-- BEGIN: taxonomy -->
    <span class="taxonomy">{taxonomy}</span>
    <!-- END: taxonomy -->
    <div class="content">{content}</div>
    <!-- BEGIN: links -->
    <div class="links">» {links}</div>
    <!-- END: links -->
--> </div>
  </div>

<!-- END: node -->

then add

.blog {
border:1px solid red;
}

or whatever to your .css file and it should work.

now, you could add {node_type} to the node class - as in

<code><div class="node {node_type} {sticky}">
                  ^^^^^^^^^


it might be harder to style, but if you are using flexinode, it might be easier to style nodes this way.

i am working on styling by taxonomy now.

erik.

Bèr Kessels’s picture

I just released a module called "sections", that allows themes per sections. The here mentioned feature can be implemented in an easy way in this module.

And if this solved you problem, would you be so kind to report back that it helped? This will help others whom are looking for the same solution.

[Ber | Drupal Services webschuur.com]

egfrith’s picture

I want forums postings to be different from story postings, and it seemed easier to do this with the changes to the xtemplate code proposed above rather than the sections code, since each forum thread seems to exist as a page node without a logical name to reference, as the sections module requires.

With the above code I can simply add class="{node_type}" to the comment and title divs in xtemplate.xtmpl and get the effects I require only in forum postings.