[Drupal] Views: pass arguments to a block

Here i will try to get the taxonomy ID from the path. 

 

1) In the view admin page under arguments click on the Taxonomy: Term ID argument and scroll down the page where you’ll see some options for that argument under Defaults: Configure Argument Taxonomy: Term ID.

 

2) Under Action to take if argument is not present select Provide default argument then under Default argument type, select PHP code.
now we can enter some custom PHP code to get the taxonomy ID from the page URL path, of course, the taxonomy ID should display in the path, for example, my_path/1000, the 1000 is a taxonomy ID.

 

3) In the PHP argument code box enter the following PHP:
<?php
if (arg(0== 'my_path' && arg(1!= '') {
  
return arg(1);
}
?>

 

4) You should select hide view / page not found in the Action to take if argument does not validate under Validator optionsthat way views will check the user exists and find the view/block is they don’t have any content.

 

5) Lastly save the view and assign your block to the my_path/1000 page.
posted @ 2011-03-02 14:09  DavidHHuan  阅读(408)  评论(0编辑  收藏  举报