0

I am working on a custom drupal user page and have run into a concatination question in php. I am a nube so thanks in advance for your help.

When I input this code:

<h2><?php echo About; ?> <?php print render($user_profile['field_first_name']); ?> </h2>

It breaks on to two lines

About
James

...instead of...

About James

Please help me concatenate.

apaderno
  • 28,547
  • 16
  • 75
  • 90

1 Answers1

1

This is because render() function adds div and other html tags to your content. If you checked the source, you will see unnecessary div tags.

If you need to get the raw value, you can try this. In your tpl.php file, add this line:

<?php print '<pre>'.print_r($user_profile['field_first_name'], 1).'</pre>'; ?>

Now you will see a nicely formatted variable listing.

it will say that $user_profile['field_first_name'] is an array, and it will list the whole array. Now, find that value you want. In most cases, it's similar to $user_profile['field_first_name']['und'][0]['value'].

Now, all you need to do is using this value instead.

<h2><?php print 'About '.check_plain($user_profile['field_first_name']['und'][0]['value']); ?> </h2>

this will put the value in same line.Note that the check_plain() function makes this value safe to be used with another html tag. If you have any trouble, let us know and lets try to figure that out :)

AKS
  • 4,618
  • 2
  • 29
  • 48