How to add View arguments in view header?

pcave - December 8, 2008 - 15:17
Project:Views
Version:6.x-2.1
Component:Code
Category:support request
Priority:normal
Assigned:gildedgod
Status:closed
Description

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

Thanks!

#1

gildedgod - January 5, 2009 - 12:17
Assigned to:Anonymous» gildedgod
Status:active» fixed

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

<?php
$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:
<?php
global $my_own_argument;
$my_own_argument = $argument;
return
true;
?>

without "< ? php" and "? >"
4. View -> Header -> Input format: PHP Code
5. View -> Header -> Value:
<?php
global $my_own_argument;
echo
"Your variable: ".$my_own_argument;
?>

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

#2

merlinofchaos - January 7, 2009 - 19:26

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

#3

gildedgod - January 10, 2009 - 11:29

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.

#4

gildedgod - January 10, 2009 - 12:08

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 :)

#5

System Message - January 24, 2009 - 12:10
Status:fixed» closed

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

#6

entrigan - July 11, 2009 - 04:47

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

 
 

Drupal is a registered trademark of Dries Buytaert.