Saturday, December 18, 2010

Combining views and path aliases in Drupal 6

Ok after a long time off, I finally have something worth to say. First I must thank styol from #drupal IRC channel for pointing me to the solution and to phrancescot for his persistent help. I decided to write it up for other people struggling like me.

What I was trying to achieve
Basically I wanted to add a Tab for a content type song that pointed to a view to report all the reviews for that song, all that using nice auto-aliased urls.

The context
The song content type
I have a song content type, it has the usual Title and Body fields plus a field called duration.
Each song content type is auto aliased using the pathauto module. The automatic alias is song/[title-raw]

The review content type
I have a content type review which basically has the usual Title and Body fields plus a nodereference field called song.

The view to list the reviews for a song
Here I won't go into the SQL query details, it's just standard view work. The important thing here is that in Views->Page there's a Page settings entry. In it, you have to field to fill: Path and Menu.
The path I was using was song/%/reviews. That was my first mistake, while it works perfectly for the SQL request, the tab was not appearing in the tab menu because of that.
Instead the right solution is to use node/%/reviews

Well at this point the path is not the beautiful aliased path. However fear not, since that's where the subpath_alias module comes into play. It will rename automatically the node/% to the autopath matching it. There's nothing to do other than installing that module (talk about drupal magic !).

Now for the menu, simply select Menu Tab and fill the title and description.  And voila, the tab will have a new entry, pointing to your aliased URL.

Modules used
CCK
views
pathauto
subpath_alias

Special thanks
From the #drupal IRC channel: styol, phrancescot for the persistent help !

4 comments:

  1. Hi, nice blog & good post. You have beautifully maintained it,Its really helpful for me, hope u have a wonderful day & awaiting for more new post. Keep Blogging! I have a Web Hosting package related blog/site.
    web hosting provider

    ReplyDelete
  2. I have to bookmark this page in order for future reference,Thank you for taking the time and effort in researching and providing these blogs that are accepting guest posts.website hosting company

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. Great information shared nice article drupal

    ReplyDelete