We would like to rearrange the output of custom fields on the basic contact view page (in Drupal, /civicrm/contact/view?cid=NNNN&reset=1) in CiviCRM 4.5 on Drupal 7. Specifically, since this is a university student organization, we have a custom field called "Class Year" (simple text, field id 31, in custom data group 1 "Enrollment information") that we would like to display in the main title, after the display name. Thus, the page headline would say Joan Smith 2017 instead of the default Joan Smith.

The template to override we found easily enough in /sites/​all/​modules/​civicrm/​templates/​CRM/​Contact/​Page/​Inline/ContactName.tpl. The question is then what is the template variable for this custom field?

We could not locate this in the documentation, and all the forum threads that come up seem to be about customizing event or contribution pages, not the contact page itself.

With debugging on, adding the &smartydebug=1 parameter to the query string on the record returns this value for {$viewCustomData}:

Array (3) 1 => Array (1) 1421 => Array (7) title => "Enrollment information" name => "enrollment_information" help_pre => "" help_post => "" collapse_display => "0" collapse_adv_display => null fields => Array (11) 31 => Array (5) field_title => "Class Year" field_type => "Text" field_data_type => "Int" field_value => "2017" options_per_line => null 2 => Array (5) [snipped]

Based on this and examples of template overrides elsewhere, we have made a number guesses, among them

{$viewCustomData.1.fields.31} {$viewCustomData.1.1421.fields.31}

but they have all been fruitless.

Google finds very few forum threads at all that even mention {$viewCustomData}, so any enlightenment is greatly appreciated.

7 Answers 7


The template ​templates/​CRM/​Contact/​Page/​Inline/ContactName.tpl does not contain any custom fields. Instead of adding smartyDebug=1 in the url, which dumps variables in the main template, try adding the smarty tag {debug} in this specific template to see the available local variables.

At minimum you will probably find the contact id, and from there you could use the api to fetch necessary data (note the api explorer can generate this syntax for you):

{crmAPI var='result' entity='Contact' action='getvalue' return="custom_1" id=123}

Since you are trying to modify the way the contact's display name appears on the summary screen, there is actually a hook for that: hook_civicrm_contact_get_displayname.

From within your hook you can use the api to fetch the value of the custom field, and append it to the display name.

  • Thanks, but I am looking for a generic solution, A different client, for instance, might want to display a custom "Degrees" field where "Nickname" is by default.
    – choster
    Mar 27, 2015 at 16:06

If this is a Drupal site, you can create a block that loads the user and the civi contact to acquire the class year field value and then use jQuery ($cj in CiviCRM) to append the field but the more I think about this, the more I think this requires a custom extension where the extension would acquire the field and use hook_civicrm_contact_get_displayname (as suggested by coleman) to modify the display name.

You could flesh it out to make it more flexible and as you've noted so that you could choose to display whatever fields you like. The caveat is that you'll need to learn the civix tool and various parts of the API so depending on your skill level, there will be some tinkering and exploration required to make it happen.


We have a custom field called "Grade/Class" for the kids in our org. This field is part of the "Child" custom field set.

The id for the custom field set is 4. The id for the custom field itself is 7. We needed the child's Grade/Class field in the Demographic section of the summary screen. So we added a row with the following code to CRM\Contact\Page\Inline\Demographics.tpl. We use:

  <!-- adding Grade/Class -->
  <div class="crm-summary-row">
    <div class="crm-label">{ts}Grade/Class{/ts}</div>
    <div class="crm-content crm-custom_data">
       {crmAPI var='result' entity='Contact' action='get' sequential=1 contact_id=$contactId return='custom_7'}
         {foreach from=$result.values item=Contact}
           {assign var='n' value=$Contact.civicrm_value_child_4_id}
  <!-- end of Grade/Class -->

In the API call (like Coleman said), you return the custom field itself, so for you, it'd be 'custom_31". Then in the assign line, the value would be $Contact.(whatever the name of your custom table is in your database plus _id to grab the info from the ID column; so perhaps: $Contact.civicrm_value_enrollment_information_1_id). The next line would be: {$viewCustomData.1.$n.fields.31.field_value} .


As with Howto hide/disable fields not needed, the best answer as of CiviCRM 5.7 is to use the Contact Summary Layout Editor extension, which enables an admin to create and rearrange arbitrary blocks of fields on the main view contact screen and to remove unwanted fields. In addition to handling core and custom fields, it includes a mechanism for managing blocks supplied by other extensions.


Assuming that:

  • "7" is the custom field's id
  • "civicrm_value_constituent_information_1" is the associated table name

the following code permit the data entry in the form

  {crmAPI var='result' entity='Contact' action='get' sequential=1 contact_id=$contactId return='custom_7'}  
  {foreach from=$result.values item=Contact}
    {if $Contact.civicrm_value_constituent_information_1_id}      
      {assign var="field_name" value="custom_7_`$Contact.civicrm_value_constituent_information_1_id`"}
      {assign var="field_name" value="custom_7_-1"}

This worked for me


but i took the "field_name" from the page source before deleteing the CustomData.tpl reference

Your Answer

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

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