Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By archard on
I want to change the title of the page slighty (that is, the text between the tags in the head) depending on whether or not the current page is a view. So I'd like some code that says something like:
if(is_view)
print $newtitle;
the question is, what can I put as a condition for the if statement?
Comments
well if you are using the
well if you are using the views module, you can change the title for that view using the title field or using the argument field. Maybe I didnt understand the question correctly?
That's true, however this is
That's true, however this is a special case because I'm using the taxonomy_term view, and I only want the title changed when the view is on certain vocabularies. This is gonna require some php code that I don't think I can enter in the title field for the view.
enter it in the header field
enter it in the header field on the edit views page and click use php code.
do some if statements and drupal_set_title()....? maybe?
Hey that worked, thanks!
Hey that worked, thanks!
For those looking for a
For those looking for a solution to this, I was able to change the title of the views page depending on what vocab the taxonomy term was from. Here's how I did it:
taxonomy_get_term_by_name() takes a string and checks if there's a term for that. If there is it loads an object with lots of info associated with it, including the vid. Drupal API FTW.
Okay. but what if your wanted
Okay. but what if your wanted to change the breadcrumb on a view? (and has nothing to do with taxonomy) Does anyone know a way to test for "view" in php?
This is all I could find: I
This is all I could find:
I tryed the if statement below in my template: which I fount here (http://stackoverflow.com/questions/247991/displaying-a-drupal-view-witho...)
...that didn't work for me?? (maybe because my view is not a list ??)
so the only way I could do it was to check the url of the view. I'd love to hear if someone has a "real" solution to this.
Detecting if the current page is a view
This solution seems to work for drupal 5
SUbscribing, greetings,
SUbscribing, greetings, Martijn
try: if ($view) print
try:
D6 solution for blocks
To access a page view from your page.tpl
You can use the following in your template.php file:
Then you cound use $view in your page.tpl
You can also do more useful things.
As an example, if you want the pager of your view to be outside of your content section you can use:
and then in your page.tpl where you want the pager:
For Drupal 7 this is the best way
Took me too long to get to the bottom of this, leaving my solution here.
I recommend doing this inside of template_preprocess_page() since we're setting up stuff for the template, not spitting out content.
Then in your page.tpl.php you can do: