Fragmented Thought

Drupal - Embedding a view with arguments



Lance Gliser

Heads up! This content is more than six months old. Take some time to verify everything still works as expected.

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.

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