Taking control of your Sitemap

There are many ways to build functionality into a Drupal site. Take a sitemap for example. A typical 'page' which is often one of the standard elements in a website design. You could say, we've got the sitemap module for that, and in most cases it does the job. But wait a second, do we really need another module for this ? Here is an alternative method.

Chances are you already have cck, views and menublock [1] on your site. At this point, you don't need the extra overhead of sitemap to create a similar page. And in addition, you will have more control over the content and display (theming) of your sitemap page. Also, using views means you can easily show certain lists which would be impossible using the module, allowing for more advanced overviews.

Setting it up this way means you need to create blocks with the required information.

  • menu trees with multiple levels using menublock
  • list of categories and terms using views (optionally using term_node_count [2] to display the number of nodes in a term)
  • other lists depending on your site architecture

In order to embed these different blocks in a node, you will need to create node regions, which are a bit different to set up in comparison to normal page regions as they are placed in your node.tpl.php and thus only used on a node display. Once the regions are in place, you can use the block visibility to display them (or the context module if you happen to use that one).

Alternatively, instead of using inner node regions - and if you are already using panels - you could accomplish the same result with a custom node panel layout. The principle is the same. Another advantage using this technique: the sitemap node now can be easily editted as a normal page node (easier and more intuitive for administrators), and doesn't have a hardcoded path /sitemap.

Example of a Drupal sitemap

You might say this approach is more work to implement. I'm not arguing this is the best way to implement a sitemap but it is more flexible and might be a better choice depending on the project.

There are many more areas in Drupal where you can walk different roads to reach similar solutions (image galleries are a notorious example). My advice would be: keep the big picture in mind to spot any architectural implications certain decisions might have while drawing up a solid building plan. But don't be afraid to experiment and test out new ideas.

[1] Alternatively, if you want to reuse existing menu blocks, you can take a look at multiblock. Though this need is negated if you use context module.

[2] term node count does introduce a new table in Drupal (for performance reasons). You can also choose to write your own simple code for this and rely on caching.

10 Small but Useful Drupal Modules (part 2)

Read More »

About

This is the company blog of
Drupal specialist Merge.nl

We are located in Breda (Netherlands) and build websites using Drupal. More about us.

Content on this blog is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Netherlands License.

Creative Commons License

Recent Comments

Social