Embedding a view with arguments

Assuming you're after putting a block in, pretty much anywhere you want, you'll need control over which url token you may be using at any point. Here's the code to read a url token, and embed a view based off it.

  1. $view = 'View_Name';
  2. $view_display = 'default'; // Or whatever display you desire
  3. $desired_token = #;
  4. $path = drupal_get_path_alias($_GET['q']); //get alias of URL
  5. $path = explode('/', $path); //break path into an array
  6. if ($path[$desired_token] != '') {
  7.   print views_embed_view($view, $view_display, str_replace('-', ' ', $path[$desired_token]));
  8. } else {
  9.   print views_embed_view($view, $view_display, 'all');
  10. }

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.