How to Add Tabs to Drupal pages

Spencer Amaral
Spencer Amaral
16
Dec 2011

How to Add Tabs to Drupal pages

comment icon12 comment(s) |

BEWARE: INCREDIBLY SIMPLE

These steps work for:

Drupal 6

Drupal 7

The Need

We had a client request come in that required for us to add a new tab to the user profile for a new page.

The Problem

How in the world of Drupal are you supposed to add a tab? Use hook_menu_alter? No. Custom Module? No. Add it to a menu somewhere? No. (I mean, if you feel like spending more time than necessary you could do the first perhaps.)

The Solution

VIEWS! I told you it would be incredibly simple.

Step 1:

Create your new view.

Step 2:

Add a display: Page

Step 3: (Important Step)

Under "Page Settings" for "Path" you will need to set the path for the page under the parent page.

For Example:

If you want to add a Tab to all of the User profiles on your website, set your path as "user/%/yourtab". (% will become the uid of the profile being viewed)

 Step 4:

  Also under "Page Settings" is "Menu", set this to "Menu Tab" or "Default Menu Tab". From there you will set your Tab's title, description and it's parent item.

Step Done:

  That's it, you're finished! Now you may run free and set up your one of a kind, mastermind view!

In Picture Book Format

 

Simple indeed, but so useful!

Subscribe to our Networks

Popular Tags by Spencer

IW on Facebook

Comments

September 18, 2012

Anonymous

Ta very much I was just about

Ta very much I was just about to start on this exact problem :)

October 7, 2012

codeninja

Thanks Mate

Yep easy !! - I Feel like a tool for making a custom module just to display some custom text in a new user tab for drupal - this has saved me alot of time today as I am just phoning it in at work today.

October 8, 2012

SAmaral

You're Welcome

That's great! I'm glad this was able to help you out.

October 9, 2012

Karen

tabs

I am working on a Drupal upgrade for my website. There are different levels of pages. The page that I need to have tabs at is the actual "document" page, which will have several tabs, which are tied to the database. Here is a list of the different tabs
Document
Transcription
Background Info
Related Documents
Related Photos
Related Cartoons
Related Maps
Related Locations
Related News Articles
Related Journal Articles
Related Magazine Articles
Suggested Books

How can I set up my Drupal so that every document page contains these tabs?
Here is a sample of what the document page would look like
http://lincolnarchives.org/alfred-purinton-1.html

Thanks much,
Karen

October 10, 2012

SAmaral

Views not quite Compatible

Hi Karen,

Had a few questions for you,

If you're using Drupal 6 or 7?

Are the Document Pages of a certain content type called Documents?

Everything Drupal does in relation to these paths is based on the current URL you have entered in. From what I have found and tested, views is not very compatible with pathauto.

So if you have these nodes set up for example as "documents/test-doc" and it has a node id of 10, then your path settings would need to be "node/6/tab-name" instead of "documents/test-doc/tab-name". And to have it display on every document page you would need to use "node/%/tab-name".

However, this will then place the tab on every node page and not just document content types. I do wish I could tell you to just use "documents/%/tab-name" and that would work, but at this point that doesn't appear to be possible.

This best way to accomplish this would be the creation of a custom module and using hook_menu function along with MENU_LOCAL_TASK. A good article showing this would be here: http://timonweb.com/how-add-tab-node-drupal

I hope this helps, thank you!

-Spencer

December 1, 2012

Anonymous

dfssgdsd sggsqgsq

dfssgdsd
sggsqgsq

December 31, 2012

Link

THANK YOU

This is awesome. I spent hours messing with hook_menu_alter and then I ran into this post and was done in 3 minutes. You are the best.

February 12, 2013

Anonymous

Hi! Very nice! Thanks for the

Hi!

Very nice! Thanks for the post!!

Regards,
Carlos.

March 2, 2013

Anonymous

Perfect!

I'm new to Drupal and the reason I'm here is because I want to write less code, not more. Every solution I found was some kind of custom code hack. I knew there had to be a better way. You win the Internet for today.

March 6, 2013

Chris Routh

Making Tab appear on page?

Hi,

Thanks for your tutorial. For the most part it worked like a charm, though I had one hiccup.

The page adds to the view as a tab as expected, however when going to the page itself, the 'View' 'Edit' etc.. tabs take over, and you can no longer see the tabs of the view.

Is there a way to have both tab sets appear together, or maybe push the local task down to the secondary local tasks to prevent the views tabs from being overridden?

Search