I've found tons of ways to do this in templates, but I need something that will work in a block.

Imagine I have a block at the bottom of a set of content pages with some javascript and html to open another website with some specific criteria. I need that criteria to come from values stored in CCK fields.

My content has an address field associated with it. field_address.

I want to have a block with PHP code that can reference the address field like:

<a href="site.com/search.asp?address=<?php print $field_address ?>">Click Here</a>

Anyone know if this is possible?

Comments

nevets’s picture

How are you choosing which node to pull the field from? If this block only shows when viewing a single node (i.e. the unaliased path is of the form node/{nid} this may help

<?php
if ( arg(0) == 'node' && is_numeric(arg(1)) ) {
  $node = node_load(arg(1));
  print l('Click here', 'http://site.com/search.asp', array(), "address=$node->field_address");
}
?>
 

The key is you need a node object and for that you generally need an node id (nid).

daytripscanada’s picture

You my friend are a life saver. Your code didn't quite do what I wanted but changing $node->field_address into $node->field_address['value'] did the trick. I am using this to get information from an Address field built with CCK to build a Google Map/Directions. I have been searching forever for a mapping module for 6.x but it appears nothing is ported yet so I decided to use some PHP and a block to get the same effect. If anyone else is interested in this concept, please let me know and i'll share the code.

Example can be seen here: Day Trips Canada - HMCS Haida