I'm trying to plan out my first Drupal site, which will begin as a simple prototype but should later become a more elaborate site serving as the public face of a growing business. I'm puzzled by one aspect of how to design the site with Drupal.

The site will have multiple pages which share an overall look and feel, but will have different content, and to a great extent, different layouts. Different types of content will appear on different pages. Some pages will need sidebars; others will have no use for them. This seems almost inevitable to me; if a web site needed only one layout and one combination of content types, it would have only one page.

But that does not seem to be how Drupal works. The appearance of every page is governed by a single layout which is created by placing blocks in a fixed order in each region of a single theme. In other words, Drupal "wants" every page on a site to look the same.

As I understand it, the pure "Drupal way" of creating a multi-page site works like this. First, define the blocks that are to appear on every page. Next, place the blocks in the theme in such a way that the blocks which are to appear on each page of the site are found in the proper region of the theme in the proper order. Then, configure each block to appear only on the page(s) where it is wanted.

That's manageable for a site that has only two or three pages, but if there were a dozen, the process would get so unwieldy that it would be impractical. And in the real world, a web site with a dozen pages is pretty darn small.

I have found several contributed modules that enable Drupal to generate different pages with different themes (and presumably different layouts): Organic Groups, Sections, Taxonomy Theme, and View-Theme. I can use one of those to do what I want (although I face the problem of deciding which one best fits my needs). I think I must be missing something basic, though: it seems implausible that the Drupal core would lack an effective means of doing something this basic.

Comments

Given you are talking in general terms it is hard to given a specific answer. But the general nature of the question provides an answer as to why Drupal does not do what you seem to want how of the box and that is control block visibility bases on some logic often thought of in terms as section of the site. There are many ways though to define what a makes up a section. I approach this problem by defining what make something a section (or more generally what are the rules for block visibility). The I write a small module that defines a helper function that based on information passed in and/or maybe on the currently viewed node or page I have the function return TRUE or FALSE. One of the arguments to the function might be an array of "sections" for which it should be visiible. No single answer here though so it takes a little customization.

And might I suggest looking at panels 2. Really nice for producing page layouts based on a node, taxonomy term and more. It can also hide regions.

It is very simple to theme per node type, even per node. Just plain core functionality.

-----------------------------------------
Joep
CompuBase, Drupal websites and design

-----------------------------------------
Joep
CompuBase, Dutch Drupal full service agency

I'm still new enough that I'm having trouble finding information in the handbooks because I'm not sure what to look for, and their on-line book structure makes things more difficult. If you could point me toward a particular part of the particular handbook, that would help a lot.

Knowing how I got here might help you understand my perspective on this. The question "how to apply different layouts to different pages?" occurred to me while I was writing a design document. The person I'm doing this for saw the question before I had made a serious attempt to answer it myself, and passed it on to someone whom he described to me as a pretty experienced Drupal developer. The answer that came back to me was, "there are ways to do it in code, but the easiest way is to use Organic Groups." I looked at Organic Groups, thought "This doesn't look right," and came here. I can't say what went wrong, but I got pointed firmly away from the idea that it could be just plain core functionality!

If I understand your question correctly, then I think this document will answer it: http://drupal.org/node/104316

This is for drupal 5.x, and I don't know if 6.x works the same way.

That approach looks good. I don't know if it will work in 6.x either, but I'll give it a try.

One question: how does it come up with the filenames it looks for? The reference gives examples, but there are not enough of them to reveal what they're examples of.

Drupal looks at the URL of the page that is being generated and looks for template files that match that name. It starts looking at the most specific (right most) part of the URL and goes to the left. Because you can control the URL of any node or view with URL Alias (or with the Path Auto module), it's easy to match the template you want.

From the above link:

For example, if you were to visit http://www.example.com/node/1/edit, PHPtemplate would look for the following templates, in descending order:

page-node-edit.tpl.php
page-node-1.tpl.php
page-node.tpl.php
page.tpl.php

The last one is the default. If nothing matches, that's the one that it will use, so all themes have that. When you look at the file names above that, notice how they relate to the URL. As you climb higher in the filenames they are more specific to the URL. The example assumes that you're already familiar with drupal's URLs, so I can see where it would be hard to see much from that. Also note the special case for the file page-front.tpl.php. You use this file name if you want your front page to be themed differently from the internal pages of your site.

Thank you. That gives me more control, but if I understand it correctly, it does not do everything I need.

My essential problem is how to display different pages which contain different content -- different blocks -- and different templates won't do that. A template receives the entire content of each region in one variable; it can display each of them as it pleases, but it has no control over what is in them.

I know that I can point the browser to any node and produce a page with that node in the content area, but I need to exercise the same type of control over every page that Administer>>Site Building>>Blocks lets me exercise over the front page. It's not clear how to do that.

Regarding the templates, let me see if I understand the rule:

Given a path name or alias http://www.example.com/name1/name2/.../namen, Drupal looks for the following template files, in order:

page-name1-namen.tpl.php
page-name1-namen-1.tpl.php
   . . .
page-name1-name2.tpl.php
page-name1.tpl.php
page.tpl.php

I guess I really don't understand what you mean by "display different pages which contain different content". Could you go into more detail or give some examples?

I'm kind of at a loss, because I don't know how I could say it more clearly. Perhaps an example will help.

Go to Yahoo's home page. You'll see a bunch of headlines, teasers, etc., a menu bar across the top, a list of section links on the left, and so forth. It's pretty easy to imagine how this could be implemented as a Drupal front page.

Now click one of the section links, say, Movies. Ignore the fact that the resulting page has a different design, color scheme, et cetera. It also has different content. There is a menu bar, but the items in it are different. There's a list of links down the left, but here they represent movies instead of sections. There are teasers in the center, but they're all about movies instead of items of general interest and news.

If you clicked the other section links you'd get other pages that were equally different from the front page, and from each other.

Leaving out the different designs and color schemes, which I do not want, this is what I need.

I'm not sure yet whether I will need different themes for different pages of the site, but every page will need its own layout and content -- not just different groups of stories, which I believe I could handle through Taxonomy, but different menus, different content in sidebars (or none, in some cases), different graphics in the header. Everything that I can do to the front page with Administer>>Site building>>Blocks, I need to be able to do separately to every page on the site.

It is mentioned before, you can create different templates for each page or content type.
In this template you can call different menus and whatever more you want to include in that page.

-----------------------------------------
Joep
CompuBase, Drupal websites and design

-----------------------------------------
Joep
CompuBase, Dutch Drupal full service agency

Does this imply that the Administer>>Site Building>>Blocks page is useful only for composing the front page, and for the rest of my site I must hand-code in PHP? That would be very disappointing, and very puzzling as well. I've read repeated assurances in documentation, blogs, etc. that one can develop useful sites in Drupal without any PHP coding at all, but it is hard for me to imagine a useful site with only one type of page.

I know there are several contributed modules that allow the use of multiple themes in one site. One developer referred me to Organic Groups (although when I studied it I had doubts that it was what I wanted). Do any of these allow multiple block layouts as well? Would one of them perhaps be a practical solution?

Perhaps I should design my site as several Drupal sites, each containing the pages that require one layout, with links back and forth between them. Can you foresee any difficulties with that? It would require a great deal of file duplication, but the disk space required would not be very great.

If you want very flexible blocks functionality, you should check out the panels (v2) module. I am not sure but I believe panels will eventually replace blocks in core.

-----------------------------------------
Joep
CompuBase, Drupal websites and design

-----------------------------------------
Joep
CompuBase, Dutch Drupal full service agency

Thank you, that looks promising. I have a couple of concerns about it, though.

The tutorial seems to begin in the middle. It starts talking about contexts without explaining what they are. I'm not even sure whether they're a Panels concept or core Drupal concept. It may take me a while to figure out whether this module is suitable for me.

Perhaps you can clarify one thing: does Panels manage the layout of the entire page, or just the content region? If the content region only, is it reasonable to let the content region take over the whole page, and make Panels present the header, menu, etc? If so it could well solve my problem, but if not, it won't really buy me anything.

Second, I'm concerned that Panels is not yet available for Drupal 6. (The contributor has just released an RC3 beta for Drupal 5, which implies that work on a Drupal 6 version has not begun.)

My client is strongly encouraging me to develop with Drupal 6. I can fall back to Drupal 5 if necessary, but I'll have to make a good case for it. I'd need to be very, very sure Panels would work for me before using it to justify that.

Personally I would not let the client choose the release of Drupal but pick the release of Drupal based on the requirements for the site.

It also sound like you want to take advantage of the abliity to use either a different page.tpl.php or theme based on the path (url). Both the section and taxonomy theme module can help with a theme based on path. The advantage is the regions/blocks can be completely different if needed. Using different page.tpl.php based on path requires adding a little code to template.php and whle flexiable each page.tpl.php uses the same regions/blocks (though it does not need to display a region).

If all you want to do is control block visibility based on path that is also possible.

I have looked briefly at the documentation for Sections, and it appears to be exactly what I need. I'm going to download it and see what I can make it do.

Thank you for sticking with me and keeping an open mind until my requirements became clear.

Personally I would not let the client choose the release of Drupal...

"Client" is a misnomer; "prime contractor" would be more accurate. The person I identified as my "client" has the final say on these issues because he negotiates the business agreement and requirements with the actual client. (He is also answerable to them for much more than this Drupal development project.)

You can use the module called Context to easily build separate layouts across the sections of your site. Here you have the link.
http://drupal.org/project/context