I'm having some difficulty identifying the variable name for a user reference field (in this case 'Web Author') that I've generated for a content type of 'article' so that I can use it in the 'submitted' area generated by template.php.

What's shown below was previously generated by someone else to allow for the string to link to articles by author, which is what I'd like to do right next to the previously generated author name. Can someone help me with identifying the proper syntax to put in and identify a user reference field? Thanks.

function c2n_preprocess_node(&$variables) {

$variables['node_content_top'] = block_get_blocks_by_region('node_content_top');
$newname = strip_tags($variables['name']);
$webname = strip_tags($content['field_web_author']); //THIS IS WHAT I CAN'T FIGURE OUT
$newname_slug = preg_replace("/[\s-]+/", " ", strtolower($newname));
$webname_slug = preg_replace("/[\s-]+/", " ", strtolower($webname));
$newname_link = '<a href="/stories-by-author/'.$newname_slug.'">'.$newname.'</a>';
$webname_link = '<a href="/stories-by-author/'.$webname_slug.'">'.$webname.'</a>';
// reformat the submitted author/dateline
$variables['submitted'] = t('!username | !webname | @datetime', array('!username' =>
$newname_link, '!webname' => $webname_link,
'@datetime' => date("F j, Y g:i a", $variables['created'])));


  • Did you try to do something like dpm($content); and check which field/array notation you need? – Sidney Gijzen May 9 '14 at 18:51
  • I did and best I can tell, its 'field_web_author' which is what I've used. I think where I'm stuck is what syntax I need to call the data itself. Where the line above it uses $variable and calls name (which works well and outputs) I'm not sure if $variable or $content (etc.) would be the right way to reference it. – bseehafer May 9 '14 at 19:08
  • Also see this question: drupal.stackexchange.com/questions/30063/… . With the help of Devel it should be possible to find the name of the field which contains the values you're looking for. I would say to use the $variables, since that's the argument passed in your function. – Sidney Gijzen May 9 '14 at 21:38
  • At this point, the best I can get it to display is the letter 'n' and the number 1. anything involving print render($content['tag']); breaks the page so I don't know how that's working. Variables seem to print out fine (setting $webname to $variables['date'] outputs the date but any attempt to output $content tags gives undesired results. I've added $content to the function declaration: function c2n_preprocess_node(&$variables, $content) ...but still am not sure if I'm even on the right path. Anyone have good experience rendering the name of a user in a user reference field? I'm stuck. – bseehafer May 12 '14 at 21:22
  • turns out this did the trick. Thanks all for steering me onto the right track. $webname = strip_tags($variables['content']['field_web_author'][0]['#title']); – bseehafer May 19 '14 at 17:55

Your Answer

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

Browse other questions tagged or ask your own question.