Answers.Body: <p>As with <em><a href="https://civicrm.stackexchange.com/questions/9416">Howto hide/disable fields not needed</a></em>, the best answer as of CiviCRM 5.7 is to use the <strong><a href="https://github.com/civicrm/org.civicrm.contactlayout" rel="nofollow noreferrer">Contact Summary Layout Editor</a></strong> 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.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-12-27T21:10:19.090Z
Answers.LastActivityDate: 2018-12-27T21:10:19.090Z
Answers.UserDisplayName: choster
Answers.Body: <p>The template <code>​templates/​CRM/​Contact/​Page/​Inline/ContactName.tpl</code> does not contain any custom fields. Instead of adding <code>smartyDebug=1</code> in the url, which dumps variables in the main template, try adding the smarty tag <code>{debug}</code> in this specific template to see the available local variables.</p>
  
  <p>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):</p>
  
  <pre><code>{crmAPI var='result' entity='Contact' action='getvalue' return="custom_1" id=123}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-03-27T16:52:10.353Z
Answers.LastActivityDate: 2015-03-27T16:52:10.353Z
Answers.UserDisplayName: Coleman
Answers.Body: <p>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. </p>
  
  <p>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.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-03-27T17:43:11.370Z
Answers.LastActivityDate: 2015-03-27T17:43:11.370Z
Answers.UserDisplayName: Andrew Wasson
Answers.Body: <p>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: <a href="http://wiki.civicrm.org/confluence/pages/viewpage.action?pageId=131399684" rel="nofollow">hook_civicrm_contact_get_displayname</a>.</p>
  
  <p>From within your hook you can use the api to fetch the value of the custom field, and append it to the display name.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-03-27T16:06:55.903Z
Answers.Text: 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.
Answers.UserDisplayName: choster
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-03-27T16:02:46.590Z
Answers.LastActivityDate: 2015-03-27T16:02:46.590Z
Answers.UserDisplayName: Coleman
Answers.Body: <p>We have a custom field called "Grade/Class" for the kids in our org. This field is part of the "Child" custom field set.</p>
  
  <p>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: </p>
  
  <pre><code>  &lt;!-- adding Grade/Class --&gt;
    &lt;div class="crm-summary-row"&gt;
      &lt;div class="crm-label"&gt;{ts}Grade/Class{/ts}&lt;/div&gt;
      &lt;div class="crm-content crm-custom_data"&gt;
         {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}
             {$viewCustomData.4.$n.fields.7.field_value}
           {/foreach}
      &lt;/div&gt;
    &lt;/div&gt;
    &lt;!-- end of Grade/Class --&gt;
  </code></pre>
  
  <p>In the API call (like Coleman said), you return the custom field itself, so for you, it'd be 'custom_31".  Then in the <em>assign</em> 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} .</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-01T15:54:31.740Z
Answers.LastActivityDate: 2015-04-01T15:54:31.740Z
Answers.UserDisplayName: Allen Hutchison
Answers.Body: <p>Assuming that:</p>
  
  <ul>
  <li>"7" is the custom field's id </li>
  <li>"civicrm_value_constituent_information_1" is the associated table name</li>
  </ul>
  
  <p>the following code permit the data entry in the form</p>
  
  <pre><code>  {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`"}
      {else}        
        {assign var="field_name" value="custom_7_-1"}
      {/if}
    {/foreach}
    {$form.$field_name.label}     
    {$form.$field_name.html}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-30T16:06:43.363Z
Answers.LastActivityDate: 2016-08-30T16:06:43.363Z
Answers.UserDisplayName: marcello
Answers.Body: <p>This worked for me</p>
  
  <pre><code>  {$form.&lt;field_name&gt;.label}
    {$form.&lt;field_name&gt;.html}
  </code></pre>
  
  <p>but i took the "field_name" from the page source before deleteing the CustomData.tpl reference</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-05-17T13:32:53.073Z
Answers.LastActivityDate: 2016-05-17T13:32:53.073Z
Answers.UserDisplayName: Zeno
Body: <p>We would like to rearrange the output of custom fields on the basic contact view page (in Drupal, /civicrm/contact/view?cid=NNNN&amp;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 <em>Joan Smith 2017</em> instead of the default <em>Joan Smith</em>.</p>
  
  <p>The template to override we found easily enough in <code>/sites/​all/​modules/​civicrm/​templates/​CRM/​Contact/​Page/​Inline/ContactName.tpl</code>. The question is then <strong>what is the template variable for this custom field</strong>?</p>
  
  <p>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.</p>
  
  <p>With debugging on, adding the <code>&amp;smartydebug=1</code> parameter to the query string on the record returns this value for {$viewCustomData}:</p>
  
  <p><code>Array (3)
  1 =&gt; Array (1)
    1421 =&gt; Array (7)
      title =&gt; "Enrollment information"
      name =&gt; "enrollment_information"
      help_pre =&gt; ""
      help_post =&gt; ""
      collapse_display =&gt; "0"
      collapse_adv_display =&gt; null
      fields =&gt; Array (11)
        31 =&gt; Array (5)
          field_title =&gt; "Class Year"
          field_type =&gt; "Text"
          field_data_type =&gt; "Int"
          field_value =&gt; "2017"
          options_per_line =&gt; null
        2 =&gt; Array (5)</code> [snipped]</p>
  
  <p>Based on this and examples of template overrides elsewhere, we have made a number guesses, among them</p>
  
  <blockquote>
    <p><code>{$custom_value_31}</code><br>
    <code>{$profileFields_1.custom_31}</code><br>
    <code>{$viewCustomData.1.fields.31}</code>
    <code>{$viewCustomData.1.1421.fields.31}</code></p>
  </blockquote>
  
  <p>but they have all been fruitless.</p>
  
  <p>Google finds very few forum threads at all that even mention {$viewCustomData}, so any enlightenment is greatly appreciated.</p>
  
Tags: <custom-fields><custom-templates><contact-view><smarty>
Title: How can I add/rearrange custom fields in the default contact view template?
ThreadText: # How can I add/rearrange custom fields in the default contact view template?
  
  (Asked by: username_0 on 2015-03-26)
  
  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
  
  > `{$custom_value_31}`  
  > `{$profileFields_1.custom_31}`  
  > `{$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.
  
  **Tags:** custom-fields, custom-templates, contact-view, smarty
  
  
  ---
  
  ## 7 answers
  
  ### Answer by username_0 on 2018-12-27. Score: 2 | Accepted answer
  
  As with *[Howto hide/disable fields not needed](https://civicrm.stackexchange.com/questions/9416)*, the best answer as of CiviCRM 5.7 is to use the **[Contact Summary Layout Editor](https://github.com/civicrm/org.civicrm.contactlayout)** 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.
  
  
  ---
  
  ### Answer by username_1 on 2015-03-27. Score: 4
  
  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}
  
  
  ---
  
  ### Answer by username_2 on 2015-03-27. Score: 2
  
  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.
  
  
  ---
  
  ### Answer by username_1 on 2015-03-27. Score: 2
  
  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](http://wiki.civicrm.org/confluence/pages/viewpage.action?pageId=131399684).
  
  From within your hook you can use the api to fetch the value of the custom field, and append it to the display name.
  
  > **Comments:**
  > **username_0**: 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.  
  
  ---
  
  ### Answer by username_3 on 2015-04-01. Score: 2
  
  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: 
    
    
      {ts}Grade/Class{/ts}
      
         {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}
             {$viewCustomData.4.$n.fields.7.field_value}
           {/foreach}
      
    
    
  
  In the API call (like username_1 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} .
  
  
  ---
  
  ### Answer by username_4 on 2016-08-30. Score: 1
  
  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`"}
      {else}        
        {assign var="field_name" value="custom_7_-1"}
      {/if}
    {/foreach}
    {$form.$field_name.label}     
    {$form.$field_name.html}
  
  
  ---
  
  ### Answer by username_5 on 2016-05-17. Score: 0
  
  This worked for me
    {$form..label}
    {$form..html}
  
  but i took the "field_name" from the page source before deleteing the CustomData.tpl reference
  
  
  ---
  
  