2

We're building a very content rich site in Drupal. It's my first time working with it. There are a variety of sections to this site, each with a different layout. I plan on determining the page.tpl.php via the phptemplate_preprocess_page() method.

My question is how best to specify where in a given page to put different chunks of secondary content. We've got a lot of sidebar type components, each with several small lists or groups of images. I think the best approach here is to define multiple regions as needed and drop in custom views (using the Views module) into these regions. Does that seem reasonable?

Update:

Regarding treating Views as queries - what confuses me is that the Views also have options to modify their appearance. I'd prefer if I could just get an array of nodes back from a View so I could operate on the data in PHP, rather than formatted markup. Is that possible?

apaderno
  • 28,547
  • 16
  • 75
  • 90
Doug P
  • 361
  • 1
  • 4
  • 15
  • Keep in mind that even if you don't output a block region in your template it will still be generated, and can decrease performance. Use display rules to ensure that blocks are only being processed if they are actually used on the page. – gapple Oct 31 '09 at 02:45
  • @D.Pfeffer: As for executing a view without rendering the result, see: http://drupal.org/node/342132 – Henrik Opel Nov 03 '09 at 21:54
  • 2
    BTW, it is not to fruitful to add a (different) follow up question like this to an already answered question, as not many people will notice it. You should ask a new question (maybe linking the original, if still related) in cases like this. – Henrik Opel Nov 03 '09 at 22:54

3 Answers3

3

Yes, you can use custom regions, and drop in custom views into them.

You can even use create custom blocks and use views in them.

It depends on the structure of the layout you have.

Rishav Rastogi
  • 15,484
  • 3
  • 42
  • 47
3

To expand a bit on Rishavs (correct) answer, blocks are the 'standard' element to fill regions. The regions in your page.tpl.php define the broad, general layout (e.g. a header, some columns/sidebars and a footer - anything you need). Within a region, you might place only one thing (e.g. a view), but usually more in the form of several blocks. The order in which they appear in the regions is determined by the blocks weight.

You can create blocks directly in the views module by adding displays of type block to a 'base' view definition. Also, every menu you define will be available as a block. It is also pretty straight forward to create your own blocks within custom modules, giving you full control over its contents (see hook_block() for this). That way, for example, you can put forms into blocks (the login block of a standard Drupal installation is an example for this).

Henrik Opel
  • 19,341
  • 1
  • 48
  • 64
1

A View (a list of content) is a database query. A region is an area of the page (left sidebar, footer, etc.). Regions are assigned in the page template (the tpl.php's) and will vary depending on the theme you are using. Typically, secondary content (including, but not limited to, Views) is placed via blocks. Blocks are displayed when they are assigned to a region ("New Users" in the "Right Sidebar"). Also, Views can also be embedded in a page template (either inside out outside of a region).

NonProfit
  • 11
  • 1
  • NonProfit, I updated my question regarding your explanation. Thanks. – Doug P Nov 03 '09 at 17:13
  • Hi D. Pfeffer, I'd suggest you look into http://drupal.org/project/devel specifically the intro video http://drupal.org/files/videocasts/moshe-theme-developer.mov It's sort of like a Firebug for Drupal. As you hover over an element on the page, this module will provide the function which generated it as well as the template (as well as potential templates which will override it) which passed it. It also provides the function arguments which have been passed and their values. – NonProfit Nov 04 '09 at 15:30