Download & Extend

Trying to use drupal_goto(x) where x is based on viewfield results.

Project:Viewfield
Version:6.x-1.0
Component:Miscellaneous
Category:support request
Priority:normal
Assigned:Unassigned
Status:active
Issue tags:drupal_goto, node redirect, PHP, random page, viewfield results

Issue Summary

I am trying to call drupal_goto(x) from within the (PHP) body of a node that has a viewfield field attached. However, I cannot figure how to access the results of the viewfield view from within the (PHP) body of the node. I have tried the approach of
'$node->field_view_source....

But this variable doesn't seem to hold the data that I want (used var_dump() to verify this). It seems to have mostly the CCK setting info for the field. This variable doesn't seem to be useful in the node template file either (however it does seem to have a couple more elements).

How can I access the results of the viewfield view (a node id from a view that, for example, picks a random node from some specified set of nodes) from within the node's (PHP) body block or from within the node template file, or somewhere else?

I know that I can display the node content by using a page-view or by using the out put of the viewfield. However, I want to goto the actual node specified by the node id.

The closest that I have gotten so far is to use an ugly session variable hack that doesn't even seem to operate reliably.
Can someone tell me how to do this? Is it possible? Does this capability need to be added to the viewfield module?

Thank you.
--Ray

Comments

#1

I was able to get it working by putting the following code in the node.tpl.php file for my content type.

In the view, I am outputting the node path field with the following text for the 'Rewrite the output of this field' of the field configuration: path_from_view=[[path]]. I then use this patten to match a regular expression. The field name for my viewfield is 'field_view_source'.

The same code doesn't seem to work in the (PHP) body block of the node itself. Apparently, the information has not yet, at that point, been added to the content of the node? It seems to work very well now and will be useful for me and perhaps for someone else as well. Here is the code:

<?php

      $raw_view_field
= $node->field_view_source[0]['view'];
     
eregi("path_from_view\=\[(.*)\]",$raw_view_field,$regs);
     
$view_field = $regs[1];
     
$targetPath = 'http://'.rtrim($_SERVER['HTTP_HOST'].base_path(),'/').$view_field;
       if (
$view_field != '')
      {
       
drupal_goto($targetPath);
      }
   
?>
nobody click here