views:

221

answers:

2

I'm building a site in Drupal and I only want to show the secondary links on the pages that use the Views I've created. I tried using the $secondary_links variable in the views-view.tpl.php but the variable is null. How can I achieve this?

A: 

Have you activated the secondary links from the theme settings? That would be:

http://example.com/admin/build/themes/settings/name_of_your_theme

I believe once you have activated the option, the variable will be populated.

EDIT: Thinking a second more, I would also comment that I am not sure if the primary and secondary links are passed to the views templates. I believe those are passed to the page.tpl.php file instead. If I am right, and for some reason you want to add that variable to those passed to the views template, you will have to use a preprocess function, like explained here.

EDIT #2: Indeed if you only need the secondary menu used in a specific views template, another approach would be to simply call menu_secondary_links() from within the template. This is not the most elegant solution ever, as it puts in a theming element something that should belong somewhere else, but it's up to you to make the call whether that menu in the views is a core functionality or a styling element.

HTH!

mac
Hi there. Yes, you are correct in that it seems I can only use the $secondary_links variable in the page.tpl.php when I would like to use it in my views only. I thought I might have to use preprocess function but as I'm new to this I thought I would make sure there isn't an easier option.
Nick Lowman
I updated my answer suggesting an easier way to get the menu in the template.
mac
Hi Mac, you're second answer worked great. At first I didn't know how to get the menu_secondary_links() to print out and then I realised that I could use 'print theme()' function to make it work. And it displays great. Thank you very much indeed.
Nick Lowman
A: 

The secondary links are as mac correctly writes only available in page.tpl.php, but if I understand you correctly, the best solution is not getting the secondary links into your view.

With your theme, the secondary links, will most likely be printed out where they should, regardless of what is being displayed, be it your views, nodes, the front page etc. Views are displayed and everything else you render, is wrapped in the page template, that controls where menus are located, regions and other fun stuff.

Now, if you don't want to alter this, the location of the menus, their styling and this stuff, you shouldn't be printing the secondary menu in your views template, you shouldn't be doing anything with it at all.

The solution is simple
It's using something that mac mentioned but in a different way: preprocess function. These functions are used to in your template.php file, to add some logic to your variables. You can alter variables or remove them altogether. What I would do, would simply be to remove the primary links, by setting the value of $primary_links to an empty text string.
This would effectively remove the primary links, so only the secondary links are displayed. You could also display the secondary links as the primary, but this might cause confusing to your users. You just need to add some logic to control when this should happen and you are set.

googletorp
Hi googletorp, I wanted to display the secondary nav only in my Views pages but Mac's suggestion to use menu_secondary_links() in the views.tpl.php worked perfectly and for the moment it's easier than using preprocess functions as I've only just started using Drupal. Many thanks for your help.
Nick Lowman

related questions