2

For the sake of theming, I need to render the output of a view into a separate region. I could create a view block, but this way I lose the ability to pass contextual arguments to it. Any suggestions?

4
  • What kind of contextual arguments are you passing to the view? Some of them you can replicate quite easily with the pass default arguent PHP field.
    – Chapabu
    Dec 16 '11 at 9:47
  • Maybe using panels would help, they are context aware. I don't have time to develop a proper answer but in such scenario's panels have an edge on blocks. COntexts could also be of help but less flexible than panels, in my very humble opinion. Dec 16 '11 at 10:39
  • @stefgosselin Well, I could rephrase my question as "how to change the target region of a panel?" Dec 16 '11 at 13:38
  • @Chapabu I'm passing taxonomy terms Dec 19 '11 at 7:46
1

There are a lot of hook for views, you can use hook_views_pre_execute or another one it depends of what you need to do.

See here the list

3
  • I need to send output of a view to another theme region. How can this be accomplished with hooks? Dec 16 '11 at 13:07
  • 1
    Your block view is in a region. So if you just have to pass a argument to this block use a hook.
    – nourcy
    Dec 16 '11 at 14:21
  • This way I have to manually parse url, don't I? Dec 19 '11 at 7:40
1

I've had to do something along these lines recently. Here's what I did:

  1. Create your view and add the Contextual argument "Has taxonomy term ID"
  2. Under "When the filter value is not available" select Provide Default Value-> PHP Code
  3. Enter the code below:

    $node = node_load(arg(1));
    if($node) {
      $tag = $node->field_primary_tag['und']['0']['tid'];
    return $tag;
    } 
    else {
      return;
    }
    

On another note - this only works for one taxonomy term, but you should be able to modify the code to fit your needs.

NOTE*

I would suggest that nourcy's answer is a more Drupal friendly one, and my answer was only a quick fix to my/your problem - PHP in blocks/views etc is generally a bad idea :-p

1
  • Nice trick! I think, bad idea is not a PHP code per se, but an ability to insert it. Dec 22 '11 at 13:15

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.