Answers.Body: <p>I don't know if this is the best answer but many of the core settings tpl's have the help text directly in the tpl, e.g. <code>&lt;span class="description"&gt;{ts}Here is the help text{/ts}&lt;/span&gt;</code>. Unless you want your users to be able to edit the help text, that seems like a good enough solution here(?), since your tpl is your own custom file to begin with.</p>
  
  <p>EDIT: An alternative:
  (Haven't tested this, just as a sketch of proof of concept.)</p>
  
  <p>In buildQuickForm in your loop add a line like this:</p>
  
  <p><code>$help_texts[$key] = $result['values'][$key]['help_text'];</code></p>
  
  <p>Then after the loop add a line:</p>
  
  <p><code>$this-&gt;assign('help_texts', $help_texts);</code></p>
  
  <p>Then in the tpl inside the loop:</p>
  
  <p><code>&lt;div class="help"&gt;({$help_texts.$elementName})&lt;/div&gt;</code></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-05-20T19:46:34.650Z
Answers.Text: Notice that I’m calling the code in the tpl file in a foreach loop.  I can’t statically set text in that loop.  Obviously I could do if/else statements to check if the element name is each one and then set the help text, but that’s not a great way of doing it.
Answers.UserDisplayName: Jason Brown
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-05-20T20:15:20.870Z
Answers.Text: Yeah, the core ones that do this don't use a loop. I guess that is an option if you're not planning to change your settings list too often. Can I also ask what is "data-something" in your buildQuickForm - if you view the source of the rendered page is there an attribute on the input element called data-something that has your help text?
Answers.UserDisplayName: Demerit
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-05-20T20:19:57.787Z
Answers.Text: Yeah, I forgot that was in there.  I had been trying to test some things in the buildQuickForm code and just used that as a temporary var to see if I could get it to populate with the help_text.
Answers.UserDisplayName: Jason Brown
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-05-20T20:22:39.713Z
Answers.Text: That could be an alternate option too then. Set a different array with your help text in buildQuickForm, keyed on the same $key, and use `$this->assign` to assign it to the template, and then access it in your smarty loop.
Answers.UserDisplayName: Demerit
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-05-20T21:54:01.597Z
Answers.Text: I think you're on to something there! I just need to figure out how to concatenate the variable name from the $key and the string in smarty. So, I'm doing this in buildQuickForm now
  
  foreach($this->_settings AS $key => $value){
    $result = civicrm_api3('Setting', 'getfields', [
     'name' => $key,
    ]);
    $this->assign($key.'-help_text', $result['values'][$key]['help_text']);
    //print_r($result['values'][$key]['help_text']);
   }
  
  I've verified that the print_r is the value I want.  My only question is, how to concatenate the variable string in smarty for the tpl file?
Answers.UserDisplayName: Jason Brown
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-05-20T22:16:07.097Z
Answers.Text: You could do it that way, or see my edited answer. If you really want to concatenate try the {assign} smarty tag.
Answers.UserDisplayName: Demerit
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-05-21T16:07:52.573Z
Answers.Text: Excellent!  The edited answer works.  I don't think it's the best way to do it, because I'm fairly certain there's a way to add it to the $elementName array by using some of the built in functionality, but for now this gets me moving forward.  I really appreciate it.  I'm not going to mark it as answered though because I'd really like to know the "correct" way of doing it.  I think the answer is somewhere on this page, but I couldn't figure it out.  https://docs.civicrm.org/dev/en/latest/framework/quickform/
Answers.UserDisplayName: Jason Brown
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-05-20T19:19:47.510Z
Answers.LastActivityDate: 2019-05-20T20:27:01.457Z
Answers.LastEditDate: 2019-05-20T20:27:01.457Z
Answers.UserDisplayName: Demerit
Body: <p>I'm using buildQuickForm in an extension to allow editing of some custom settings.  It's working well, but when I created the custom settings there was a field called, "help_text".  I can't seem to figure out how to display the "help_text" in the form elements.</p>
  
  <p>I create the settings in a page called givingstatements.setting.php and this is the code from that page</p>
  
  <p>/*
   * <a href="https://github.com/artfulrobot/uk.artfulrobot.civicrm.autogroup/blob/master/settings/autogroup.setting.php" rel="nofollow noreferrer">https://github.com/artfulrobot/uk.artfulrobot.civicrm.autogroup/blob/master/settings/autogroup.setting.php</a>
   */
  return array(</p>
  
  <pre><code>/*
   * When to show legal statement on giving statements
   */
  'givingstatements_show_legal_statement' =&gt; array(
      'title' =&gt; 'Always show legal statement on giving statements',
      'group_name' =&gt; 'givingstatements_show_legal_statement',
      'group' =&gt; 'CiviCRM Preferences',
      'name' =&gt; 'givingstatements_show_legal_statement',
      'type' =&gt; 'String',
      'default' =&gt; '0',
      'add' =&gt; '4.7',
      'is_domain' =&gt; 1,
      'is_contact' =&gt; 0,
      'description' =&gt; 'Always show legal statement on giving statements.',
      'help_text' =&gt; 'If no, legal statement will only appear on statements that are 1 full year',
      'quick_form_type' =&gt; 'YesNo', // Without this it will not appear on the settings form.
      //'quick_form_type' =&gt; 'Element', // Without this it will not appear on the settings form.
      'html_type' =&gt; 'radio',
  ),
  
  /*
   * Default option for combining giving statements for spouses
   */
  'givingstatements_combine_spouse_default' =&gt; array(
      'title' =&gt; 'Combine giving statements for spouses by default',
      'group_name' =&gt; 'givingstatements_combine_spouse_default',
      'group' =&gt; 'CiviCRM Preferences',
      'name' =&gt; 'givingstatements_combine_spouse_default',
      'type' =&gt; 'String',
      'default' =&gt; '0',
      'add' =&gt; '4.7',
      'is_domain' =&gt; 1,
      'is_contact' =&gt; 0,
      'description' =&gt; 'Combine giving statements for spouses by default.',
      'help_text' =&gt; 'User preferences will override this option.',
      'quick_form_type' =&gt; 'YesNo', // Without this it will not appear on the settings form.
      //'quick_form_type' =&gt; 'Element', // Without this it will not appear on the settings form.
      'html_type' =&gt; 'radio',
  ),
  
  /*
   * Allow individuals without civicontribute access to enter custom date ranges
   */
  'givingstatements_custom_date_range_allowed' =&gt; array(
      'title' =&gt; 'Allow individuals without civicontribute access to enter custom date ranges',
      'group_name' =&gt; 'givingstatements_custom_date_range_allowed',
      'group' =&gt; 'CiviCRM Preferences',
      'name' =&gt; 'givingstatements_custom_date_range_allowed',
      'type' =&gt; 'String',
      'default' =&gt; '0',
      'add' =&gt; '4.7',
      'is_domain' =&gt; 1,
      'is_contact' =&gt; 0,
      'description' =&gt; 'Allow individuals without civicontribute access to enter custom date ranges.',
      'help_text' =&gt; 'If set to no, individuals will only be able to select full years.',
      'quick_form_type' =&gt; 'YesNo', // Without this it will not appear on the settings form.
      //'quick_form_type' =&gt; 'Element', // Without this it will not appear on the settings form.
      'html_type' =&gt; 'radio',
  ),
  );
  </code></pre>
  
  <p>My page that creates the form is called Settings.php and the code on that page is this
  <a href="https://i.sstatic.net/ZqzZE.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/ZqzZE.jpg" alt="enter image description here"></a></p>
  
  <p>My tpl page has this code</p>
  
  <pre><code>  {foreach from=$elementNames item=elementName}
  &lt;div class="crm-section"&gt;
    &lt;div class="label"&gt;{$form.$elementName.label}&lt;/div&gt;
    &lt;div class="content"&gt;{$form.$elementName.html}&lt;/div&gt;
    &lt;div class="help"&gt;({$form.$elementName.help_text})&lt;/div&gt;
    &lt;div class="clear"&gt;&lt;/div&gt;
  &lt;/div&gt;
  {/foreach}
  </code></pre>
  
  <p>But $form.$elementName.help_text is empty
  If I do {$form.$elementName|@debug_print_var} I get the array and it doesn't contain help_text, or the contents of help_text under a different key.  It outputs</p>
  
  <p>(Array (11)
  name => "givingstatements_show_legal_statement"
  value => "1"
  type => "group"
  frozen => false
  required => true
  error => null
  label => " Always show legal statement ..."
  separator => null
  html => " Array (9)
    name => "givingstatements_show_legal_statement"
    value => "1"
    type => "radio"
    frozen => false
    required => false
    error => null
    id => "CIVICRM_QFID_1_givingstatements_show_..."
    label => " " Array (9)
    name => "givingstatements_show_legal_statement"
    value => "0"
    type => "radio"
    frozen => false
    required => false
    error => null
    id => "CIVICRM_QFID_0_givingstatements_show_..."
    label => " "
  
  <p>If I go to the CiviCRM api page I can return the help_text there so I know it's storing it.
  <a href="https://i.sstatic.net/3LiLv.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/3LiLv.jpg" alt="enter image description here"></a></p>
  
Tags: <extension>
Title: How to show help_text on buildQuickForm elements
ThreadText: # How to show help_text on buildQuickForm elements
  
  (Asked by: username_0 on 2019-05-20)
  
  I'm using buildQuickForm in an extension to allow editing of some custom settings. It's working well, but when I created the custom settings there was a field called, "help\_text". I can't seem to figure out how to display the "help\_text" in the form elements.
  
  I create the settings in a page called givingstatements.setting.php and this is the code from that page
  
  /\*
  \* <https://github.com/artfulrobot/uk.artfulrobot.civicrm.autogroup/blob/master/settings/autogroup.setting.php>
  \*/
  return array(
  
  ```
  /*
   * When to show legal statement on giving statements
   */
  'givingstatements_show_legal_statement' => array(
      'title' => 'Always show legal statement on giving statements',
      'group_name' => 'givingstatements_show_legal_statement',
      'group' => 'CiviCRM Preferences',
      'name' => 'givingstatements_show_legal_statement',
      'type' => 'String',
      'default' => '0',
      'add' => '4.7',
      'is_domain' => 1,
      'is_contact' => 0,
      'description' => 'Always show legal statement on giving statements.',
      'help_text' => 'If no, legal statement will only appear on statements that are 1 full year',
      'quick_form_type' => 'YesNo', // Without this it will not appear on the settings form.
      //'quick_form_type' => 'Element', // Without this it will not appear on the settings form.
      'html_type' => 'radio',
  ),
  
  /*
   * Default option for combining giving statements for spouses
   */
  'givingstatements_combine_spouse_default' => array(
      'title' => 'Combine giving statements for spouses by default',
      'group_name' => 'givingstatements_combine_spouse_default',
      'group' => 'CiviCRM Preferences',
      'name' => 'givingstatements_combine_spouse_default',
      'type' => 'String',
      'default' => '0',
      'add' => '4.7',
      'is_domain' => 1,
      'is_contact' => 0,
      'description' => 'Combine giving statements for spouses by default.',
      'help_text' => 'User preferences will override this option.',
      'quick_form_type' => 'YesNo', // Without this it will not appear on the settings form.
      //'quick_form_type' => 'Element', // Without this it will not appear on the settings form.
      'html_type' => 'radio',
  ),
  
  /*
   * Allow individuals without civicontribute access to enter custom date ranges
   */
  'givingstatements_custom_date_range_allowed' => array(
      'title' => 'Allow individuals without civicontribute access to enter custom date ranges',
      'group_name' => 'givingstatements_custom_date_range_allowed',
      'group' => 'CiviCRM Preferences',
      'name' => 'givingstatements_custom_date_range_allowed',
      'type' => 'String',
      'default' => '0',
      'add' => '4.7',
      'is_domain' => 1,
      'is_contact' => 0,
      'description' => 'Allow individuals without civicontribute access to enter custom date ranges.',
      'help_text' => 'If set to no, individuals will only be able to select full years.',
      'quick_form_type' => 'YesNo', // Without this it will not appear on the settings form.
      //'quick_form_type' => 'Element', // Without this it will not appear on the settings form.
      'html_type' => 'radio',
  ),
  );
  
  ```
  
  My page that creates the form is called Settings.php and the code on that page is this
  [![enter image description here](https://i.sstatic.net/ZqzZE.jpg)](https://i.sstatic.net/ZqzZE.jpg)
  
  My tpl page has this code
  
  ```
    {foreach from=$elementNames item=elementName}
  <div class="crm-section">
    <div class="label">{$form.$elementName.label}</div>
    <div class="content">{$form.$elementName.html}</div>
    <div class="help">({$form.$elementName.help_text})</div>
    <div class="clear"></div>
  </div>
  {/foreach}
  
  ```
  
  But $form.$elementName.help\_text is empty
  If I do {$form.$elementName|@debug\_print\_var} I get the array and it doesn't contain help\_text, or the contents of help\_text under a different key. It outputs
  
  (Array (11)
  name => "givingstatements\_show\_legal\_statement"
  value => "1"
  type => "group"
  frozen => false
  required => true
  error => null
  label => " Always show legal statement ..."
  separator => null
  html => " Array (9)
  name => "givingstatements\_show\_legal\_statement"
  value => "1"
  type => "radio"
  frozen => false
  required => false
  error => null
  id => "CIVICRM\_QFID\_1\_givingstatements\_show\_..."
  label => " " Array (9)
  name => "givingstatements\_show\_legal\_statement"
  value => "0"
  type => "radio"
  frozen => false
  required => false
  error => null
  id => "CIVICRM\_QFID\_0\_givingstatements\_show\_..."
  label => " "
  
  If I go to the CiviCRM api page I can return the help\_text there so I know it's storing it.
  [![enter image description here](https://i.sstatic.net/3LiLv.jpg)](https://i.sstatic.net/3LiLv.jpg)
  
  **Tags:** extension
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-05-20. Score: 2
  
  I don't know if this is the best answer but many of the core settings tpl's have the help text directly in the tpl, e.g. `<span class="description">{ts}Here is the help text{/ts}</span>`. Unless you want your users to be able to edit the help text, that seems like a good enough solution here(?), since your tpl is your own custom file to begin with.
  
  EDIT: An alternative:
  (Haven't tested this, just as a sketch of proof of concept.)
  
  In buildQuickForm in your loop add a line like this:
  
  `$help_texts[$key] = $result['values'][$key]['help_text'];`
  
  Then after the loop add a line:
  
  `$this->assign('help_texts', $help_texts);`
  
  Then in the tpl inside the loop:
  
  `<div class="help">({$help_texts.$elementName})</div>`
  
  > **Comments:**
  > **username_0**: Notice that I’m calling the code in the tpl file in a foreach loop.  I can’t statically set text in that loop.  Obviously I could do if/else statements to check if the element name is each one and then set the help text, but that’s not a great way of doing it.  
  > **username_1**: Yeah, the core ones that do this don't use a loop. I guess that is an option if you're not planning to change your settings list too often. Can I also ask what is "data-something" in your buildQuickForm - if you view the source of the rendered page is there an attribute on the input element called data-something that has your help text?  
  > **username_0**: Yeah, I forgot that was in there.  I had been trying to test some things in the buildQuickForm code and just used that as a temporary var to see if I could get it to populate with the help_text.  
  > **username_1**: That could be an alternate option too then. Set a different array with your help text in buildQuickForm, keyed on the same $key, and use `$this->assign` to assign it to the template, and then access it in your smarty loop.  
  > **username_0**: I think you're on to something there! I just need to figure out how to concatenate the variable name from the $key and the string in smarty. So, I'm doing this in buildQuickForm now  foreach($this->_settings AS $key => $value){   $result = civicrm_api3('Setting', 'getfields', [    'name' => $key,   ]);   $this->assign($key.'-help_text', $result['values'][$key]['help_text']);   //print_r($result['values'][$key]['help_text']);  }  I've verified that the print_r is the value I want.  My only question is, how to concatenate the variable string in smarty for the tpl file?  
  > **username_1**: You could do it that way, or see my edited answer. If you really want to concatenate try the {assign} smarty tag.  
  > **username_0**: Excellent!  The edited answer works.  I don't think it's the best way to do it, because I'm fairly certain there's a way to add it to the $elementName array by using some of the built in functionality, but for now this gets me moving forward.  I really appreciate it.  I'm not going to mark it as answered though because I'd really like to know the "correct" way of doing it.  I think the answer is somewhere on this page, but I couldn't figure it out.  https://docs.civicrm.org/dev/en/latest/framework/quickform/  
  
  ---
  
  