0

I'm trying to print render inside my node--article.tpl.php two of Locations sub-fields: the Street address and City so that it looks like this: 16 Fleet Street, London -- without printing all other parameters (Province, Country etc) So far I've got

<?php
    print 
        render($content['field_location'][0]['#street']) . ', ' . 
        render($content['field_location'][0]['#city']);
?>

But it doesn't work. Can someone please help?

  • 1
    Does <?php print dsm($content); ?> return an array with ['field_location']? – Steven Sep 27 '13 at 19:32
  • I included your line in my node--article.tpl.php and it broke the site. – drupalina Sep 27 '13 at 19:36
  • Sorry I forgot to say you need devel module to so dsm, just so a print_r – Steven Sep 27 '13 at 19:37
1

If you have devel module installed than you check the exact contents of the array as: dsm($content);
Even if you don't have the devel module installed than check the contents of array as:

echo '<PRE>';
print_r($content);
echo '</PRE>';

I guess you probably have missed the language attribute - for regular non-location fields it's: $content['field_location']['und'][0]['#street']; and $content['field_location'][0]['#city'];

  • I entered your lines with PRE and /PRE and for Location field I found this: [field_location] => Array ( [und] => Array ( [0] => Array ( [lid] => 31 [name] => [street] => boulevard de smet de naeyer 18 [additional] => [city] => Bruxelles [province] => BRU [postal_code] => 1090 [country] => be [latitude] => 50.871899 [longitude] => 4.326884 [source] => 3 [is_primary] => 0 [province_name] => Brussels [country_name] => Belgium ) ) – drupalina Sep 27 '13 at 19:49
  • so here is solution for you: $content['field_location']['und'][0]['street']; and $content['field_location']['und'][0]['city'] – Ankit Agrawal Sep 27 '13 at 19:57
  • I added <?php print render($content['field_location']['und'][0]['#street']); ?> and it brings out nothing. On the other hand, <?php print render($content['field_location']); ?> prints ALL parameters of this field,while I only need "street" and "city". – drupalina Sep 27 '13 at 20:00
  • please remove "#" from street and city, just try this: $content['field_location']['und'][0]['street']; and $content['field_location']['und'][0]['city']; – Ankit Agrawal Sep 27 '13 at 20:02
  • <?php print render($content['field_location']['und'][0]['street']); ?>and <?php print render($content['field_location']['und'][0]['city']); ?> don't work either. – drupalina Sep 27 '13 at 20:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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