i have a content-type with this fields:

title field
starting letter // term reference -> stores term in vocab "starting letter"
car brand // term reference -> stores term in vocab "car brand"
car model // term reference -> stores term in vocab "car model"
Image field

i have created a view that hast the url: example.com/vehicles/audi (the term audi comes from the vocab "car brand" in views this looks like vehicles/%)

on this page with the url example.com/vehicles/audi i want to show a block that contains a list of other cars which name starts with the letter A like:

Alfa Romeo

the same should be work with brand starting with B, C and so on. i need a contextual solution.

my problem and what i dont unterstand: how do i set this thing up, because i dont have the term "A" in my url which i could filter with the contextual filter. i just have the term "audi". can anyone help me please?

2 Answers 2


Set argument for second view using hook_views_pre_view().

  • thank your for your reply. i should mention that i havent used the views API yet. i copied the code $view->set_arguments(array('A')); in my view under context.filter / PHP contextual filter code but this doesnt work right now. comes the hook_views_pre_view() elsewere? second thing is, as i understand this blockview will always filter for the term "A". what i need is if the url changes for expample to example.com/vehicles/bmw the filter argument should be the term "B" from the vocab.
    – clayevans
    Mar 27, 2013 at 15:13
  • Not enough space in comment, answering below Mar 27, 2013 at 20:05

I never use php in admin interface, in my opinion it's not right. Because later it's too difficult to remember where you place your custom logic... I advise you to create a custom module and place your code there.

As for your method, I guess PHP contextual filter requires returnable value. So let's try this:

$parent_view = views_get_page_view(); // Get vehicle view
$arg = $parent_view->args[0]; // Get vehicle view argument
$letter = $arg[0]; // First letter of argument
return drupal_strtoupper($letter);
  • ok i have found this. what u think of it? 'code' $view->set_arguments(array_pop(explode('/',drupal_get_path_alias()))); $output = $view->preview(); print $output; 'code' is this noob php?
    – clayevans
    Mar 29, 2013 at 16:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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