0

The situation should be common: I have a content class with one location field; in the page view of the class I show the location on map. But, at the top of the page, I want to print the address too.

In the 'manage display' of my content type, I can choose for 'map only' (formatter location_map); which is perfect for the map, or for 'default (address only)' (formatter location_default), which is perfect for the top of the page.

It is probably as easy as, something like, in the node.tpl.php, saying

// address here
$content['field_location']['#formatter']="location_default";
drupal_render($content['field_location']);

// google map here
$content['field_location']['#formatter']="location_map";
drupal_render($content['field_location']);

but that doesnt work. I also notice Location has a theming hook, described here

http://drupal.org/node/62486

unfortunately they forget to mention what goes in there. whatever i put in there, it doesnt pass to location.tpl.php (allthough it does pass that template in vain).

I have a workaround thats so ugly I'm not even going to post it here :-) Does anyone know how to do this properly ?

*-pike

1 Answer 1

2

Ah, ..in my node.tpl.php

// address here
$fvf = field_view_field('node', $node, 'field_location', array(
    'type'=>'location_default')
);
print render($fvf);

// google map here
print render($content['field_location']);

Great article: http://www.computerminds.co.uk/articles/rendering-drupal-7-fields-right-way

pfew, *-pike

1
  • You should mark this post as answer even it is your own. Nov 30, 2013 at 13:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.