How can I access the view arguments via PHP in the view header field in views 2 with Drupal 6?

Thanks!

Comments

gildedgod’s picture

Assigned: Unassigned » gildedgod
Status: Active » Fixed

1. Add into index.php before "require_once './includes/bootstrap.inc';" your own variable:

$my_own_argument = 1;
require_once './includes/bootstrap.inc';

2. View -> Arguments -> Validator options -> Validator: PHP Code
3. View -> Arguments -> Validator options -> PHP argument code:

global $my_own_argument;
$my_own_argument = $argument;
return true;

without "< ? php" and "? >"
4. View -> Header -> Input format: PHP Code
5. View -> Header -> Value:

global $my_own_argument;
echo "Your variable: ".$my_own_argument;

There may be more accurate ways, but idea is the same)

merlinofchaos’s picture

Or in the PHP in your header just use $view = views_get_current_view() and check $view->args

gildedgod’s picture

Or in the PHP in your header just use $view = views_get_current_view() and check $view->args

Unfortunately this method didn't worked for me using views2 as CCK-field through Viewfield.

gildedgod’s picture

And of course modifying core scripts for adding your variables is a bad idea =)

Add into index.php

- this is just an example, for production sites you must find another way to add global variables :)

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

entrigan’s picture

For future reference, Merlins method in #2 does work, even with ViewReference module