You are here:
» How To Pass Arguments In Drupal 6 Views?
How to pass arguments in Drupal 6 Views?
This Comment will be submitted for moderation and will not be accessible to other users until it has been approved.
I have installed drupal 6 views and now I need to pass argument to Drupal views from the url. How do I do that?
Cheers,
Mona

1 year 41 weeks ago
Tags:
Here's how you would do it:
1) In the view admin page under arguments click on the User:name argument and scroll down the page where you'll see some options for that argument under "Block: Configure Argument User: Name".
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 username from the page URL assuming your username is the second argument in the URL
ie. publications/USERNAME
3) Now in the "PHP argument code" box enter the following PHP:
<?php
if (arg(0) == 'publications' && arg(1) != '') {
return arg(1);
}
?>
Again I'm assuming the URL is publications/USERNAME and what we are saying here is if the first URL argument is "publications" and the second URL argument is not blank then use the second argument as the views username argument.
4) You should select "hide view / page not found" in the "Action to take if argument does not validate" under "Validator options" that 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 publications/USERNAME page.
Post Comment