3

What is the correct method of getting term name in the page title field if I have passed the term id in contextual filter. I have added the Content: Has taxonomy term ID contextual filter in views, I have tried to overwrite the page title be provide "%1" but that also provides term id as the "filter value type" contains term ID.

One way to achieve this using the "global php" field in the header and getting the term ID from the argument as "arg(1)", and getting the term name from the term ID and than setting page title using "drupal_set_title($term_name)".

enter image description here

enter image description here

8
  • How did you give the override option? It works fine that way.. Sep 30, 2013 at 14:47
  • Thanks for reply, but I have tried that by providing "%1" in override title link, and it is than displaying the term id but I require the term name. Sep 30, 2013 at 14:54
  • could you take a screenshot of the views config screen and post it in the question. Sep 30, 2013 at 14:59
  • @MohammedShameem Added :) Sep 30, 2013 at 15:57
  • you should try removing the % from the path and make the path just product-category Sep 30, 2013 at 16:02

2 Answers 2

2

Answers Updated: try this hook, hook_view_pre_render()

This hook is called right before the render process. The query has been executed, and the pre_render() phase has already happened for handlers, so all data should be available.

function MYMODULE_views_pre_render(&$view) {
  if ($view->name == 'your_view_name') {
     $term = taxonomy_term_load(arg('arg_position_in_url'));
     $title = $term->name;
     $view->build_info['title'] = $title;
  }
}
4
  • Thanks Arpit, I have mentioned this solution in the question. This is definitely one of the possible solution, but I am trying to see If we can have some better solution. Sep 30, 2013 at 16:50
  • check with updated answer
    – arpitr
    Sep 30, 2013 at 17:04
  • @ankit please did that work for you? or you got better way to do this, please share if so
    – arpitr
    Oct 1, 2013 at 7:44
  • I am waiting to see if we can some better alternative, otherwise this is definitely one to go with. Oct 1, 2013 at 7:57
0

Got the solution:

The mistake I was doing was selecting the "Display all results for the specified field" for the "When the filter value is NOT in the URL" field of contextual filter, Instead I was supposed to do the following for this field:

  • Check "Provide default value".
  • Select Type: "Taxonomy term ID from URL"
  • Select checkbox: "Load default filter from term page"

and rest everything as mentioned in the question.

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.