0

I'm not sure how to ask it, so if you need anymore additional information, please ask for it!

Situation
I've got a website in three languages. I got a lot of customer cases online each connected to a sector (depending in which sector they belong). Each sector and reference has it's own unique nid.

In my template.php it's stated like this:

if ('sector' == $vars['node']->type) {
        $lang = '/'.$vars['language'].'/';

        $key_path = $_SERVER['REQUEST_URI'];
        $key_path = substr_count($key_path, $lang) ? substr($key_path, strlen($lang)) : $key_path;
        if (strpos($key_path, '?')) $key_path = substr_replace($key_path, '', strpos($key_path, '?'));

        if (strpos($key_path, 'sectors-references') === 0) {        
            $view = views_get_view('references');
            if (!empty($view)) {
                $view->set_arguments((int)$vars['node']->nid);  
                $vars['content']['suffix'] = $view->render();

            }
        }
    }

And yet, every sector shows me the same references... What do I have to change to get the correct reference under the right sector?

apaderno
  • 28,547
  • 16
  • 75
  • 90
Michiel
  • 7,855
  • 16
  • 61
  • 113
  • `echo $vars['nid'] = $view-render();`?? Surely that should be `$vars['my_var'] = $view->render();` or is that just a typo in the question? – Clive Oct 12 '11 at 14:03
  • Oh damn, you're right. I corrected my mistake! – Michiel Oct 12 '11 at 14:17

1 Answers1

2

Usually arguments are passed to set_arguments using an array, if you pass a non-array the argument will probably be ignored which is why you're always getting the same result. Try:

$view->set_arguments(array((int)$vars['node']->nid));
Clive
  • 36,918
  • 8
  • 87
  • 113
  • Awesome!! You solved it! Can you give a additional explanation perhaps? – Michiel Oct 12 '11 at 14:42
  • 1
    I think the easiest way to explain it is that `set_arguments` expects it's first parameter to be an array of the arguments for the view. That way it can just run through the array rather than taking an arbitrary number of parameters to the function and having to run through `func_get_args` or something similar. Because you were passing a non-array as the parameter the `set_arguments` function just ignored it. Therefore you would get *all* results, not filtered ones – Clive Oct 12 '11 at 14:57