Answers.Body: <p>Might just be a typo but you need <code>==</code> instead of <code>=</code>.</p>
  <p><code>{if $contact.contact_sub_type == 'Student'}</code></p>
  <p>But contact_sub_type is an array, so you could foreach over it and check if one of the values is Student.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-03-16T22:14:03.147Z
Answers.Text: Thanks! That was not a typo--just the scribbles of a bumbling idiot giving it a shot in the dark. I added the double == but it still does not work for any logins. If I remove the IF statement it does work but for all contact types.
Answers.UserDisplayName: Iowa Boy
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-03-16T22:21:17.460Z
Answers.Text: Oh, it's because contact_sub_type is an array, so you could foreach thru it and check if one of the values is Student.
Answers.UserDisplayName: Demerit
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-03-17T02:02:12.160Z
Answers.Text: I am trying to just get to the contact_sub_type sub array, but not getting there. How do I get to the sub array?                                                                                              
   {crmAPI var='result' entity='Contact' action='get' id=$contactId sequential=0}
  {foreach from=$result.values item=contact name=outer_loop}
    
      Name: {$contact.display_name}</br>
      Contact Type: {$contact.contact_type}</br>
      Sub Contact Type: {foreach from=$contact.contact_sub_type item=sub name=inner_loop}{$sub}, {foreachelse}<i>Nothing to see here</i>{/foreach}
  {/foreach}
Answers.UserDisplayName: Iowa Boy
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-03-17T02:51:30.727Z
Answers.Text: That looks ok. You can use `{debug}` after the crmAPI call to pop up a box that will show you what smarty thinks the variables are.
Answers.UserDisplayName: Demerit
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-03-17T04:18:05.663Z
Answers.Text: Thanks!!! Duh, the $ContactId I was testing on did not have a sub_type so of course it was not turning up any results. Once I saw the debug was empty I realized my error.
Answers.UserDisplayName: Iowa Boy
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-03-17T04:21:44.797Z
Answers.Text: In case someone is looking for some code like this...{crmAPI var='result' entity='Contact' action='get' id=$contactId sequential=0}
  {debug}
  {foreach from=$result.values item=contact name=outer_loop}
    
      {foreach from=$contact.contact_sub_type item=sub name=inner_loop}
          {if $sub == 'Student'}
          
              {* Put in what you want to display for sub_types "Students" *}
          
          {/if}
      {/foreach}
  {/foreach}
Answers.UserDisplayName: Iowa Boy
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-03-16T19:14:07.480Z
Answers.LastActivityDate: 2021-03-16T22:22:45.193Z
Answers.LastEditDate: 2021-03-16T22:22:45.193Z
Answers.UserDisplayName: Demerit
Body: <p>Drupal 7.78
  Civi 5.28.2</p>
  <p>I am setting up a custom contact dashboard following <a href="https://civicrm.stackexchange.com/questions/31924/displaying-custom-contact-fields-in-contact-dashboard">Demerit's answer</a> using UserDashBoard.extra.tpl and smarty's crmAPI.</p>
  <p>But I only want it to be for contact sub-type = Student. How would I write an IF statement for that?</p>
  <p>Here is my best guess but it does not work.</p>
  <pre><code>    {crmAPI var='result' entity='Contact' action='get' id=$contactId sequential=0}
  {foreach from=$result.values item=contact}
    {if $contact.contact_sub_type = 'Student'}
  
  &lt;table class=&quot;dashboard-custom&quot;&gt;&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Student Demographics&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt;
  {crmAPI entity='Contact' action='get' var='result' id=$contactId return=&quot;birth_date,gender_id,custom_108,custom_107,custom_109,custom_110&quot; sequential=0}
  {foreach from=$result.values item=contact}
    &lt;tr&gt;&lt;th&gt;Date of Birth&lt;/th&gt;&lt;th&gt;Gender&lt;/th&gt;&lt;th&gt;Student Status&lt;/th&gt; &lt;th&gt;Marital Status&lt;/th&gt;&lt;th&gt;Anniversary&lt;/th&gt;&lt;th&gt;# of Children&lt;/th&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;{$contact.birth_date}&lt;/td&gt;
    &lt;td&gt;{$contact.gender_id}&lt;/td&gt;
    &lt;td&gt;{$contact.custom_108}&lt;/td&gt;
    &lt;td&gt;{$contact.custom_107}&lt;/td&gt;
    &lt;td&gt;{$contact.custom_110}&lt;/td&gt;
    &lt;td&gt;{$contact.custom_109}&lt;/td&gt;&lt;/tr&gt;
  {/foreach}
  &lt;tr&gt;&lt;td&gt;&lt;strong&gt;Class Info&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt;
  {crmAPI var='result' entity='Contact' action='get' id=$contactId return=&quot;custom_118,custom_112,custom_113,custom_111&quot;}
  {foreach from=$result.values item=contact}
  &lt;tr&gt;&lt;th&gt;Class of&lt;/th&gt;&lt;th&gt;Campus&lt;/th&gt;&lt;th&gt;CG Leader&lt;/th&gt; &lt;th&gt;Met Spouse at RI&lt;/th&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td&gt;{$contact.custom_118}&lt;/td&gt;
    &lt;td&gt;{$contact.custom_112}&lt;/td&gt;
    &lt;td&gt;{$contact.custom_113}&lt;/td&gt;
    &lt;td&gt;{$contact.custom_111}&lt;/td&gt;&lt;/tr&gt;
  {/foreach}
  &lt;/table&gt;
  {/if}
  {/foreach}
  </code></pre>
  <p>Thanks</p>
  
Tags: <smarty>
Title: Display custom contact dashboard only to certain Contact subtypes
ThreadText: # Display custom contact dashboard only to certain Contact subtypes
  
  (Asked by: username_0 on 2021-03-16)
  
  Drupal 7.78
  Civi 5.28.2
  I am setting up a custom contact dashboard following username_1's answer using UserDashBoard.extra.tpl and smarty's crmAPI.
  But I only want it to be for contact sub-type = Student. How would I write an IF statement for that?
  Here is my best guess but it does not work.
      {crmAPI var='result' entity='Contact' action='get' id=$contactId sequential=0}
  {foreach from=$result.values item=contact}
    {if $contact.contact_sub_type = 'Student'}
  
  Student Demographics
  {crmAPI entity='Contact' action='get' var='result' id=$contactId return="birth_date,gender_id,custom_108,custom_107,custom_109,custom_110" sequential=0}
  {foreach from=$result.values item=contact}
    Date of BirthGenderStudent Status Marital StatusAnniversary# of Children
    {$contact.birth_date}
    {$contact.gender_id}
    {$contact.custom_108}
    {$contact.custom_107}
    {$contact.custom_110}
    {$contact.custom_109}
  {/foreach}
  Class Info
  {crmAPI var='result' entity='Contact' action='get' id=$contactId return="custom_118,custom_112,custom_113,custom_111"}
  {foreach from=$result.values item=contact}
  Class ofCampusCG Leader Met Spouse at RI
    {$contact.custom_118}
    {$contact.custom_112}
    {$contact.custom_113}
    {$contact.custom_111}
  {/foreach}
  
  {/if}
  {/foreach}
  
  Thanks
  
  **Tags:** smarty
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2021-03-16. Score: 1 | Accepted answer
  
  Might just be a typo but you need `==` instead of `=`.
  
  `{if $contact.contact_sub_type == 'Student'}`
  
  But contact\_sub\_type is an array, so you could foreach over it and check if one of the values is Student.
  
  > **Comments:**
  > **username_0**: Thanks! That was not a typo--just the scribbles of a bumbling idiot giving it a shot in the dark. I added the double == but it still does not work for any logins. If I remove the IF statement it does work but for all contact types.  
  > **username_1**: Oh, it's because contact_sub_type is an array, so you could foreach thru it and check if one of the values is Student.  
  > **username_0**: I am trying to just get to the contact_sub_type sub array, but not getting there. How do I get to the sub array?                                                                                                {crmAPI var='result' entity='Contact' action='get' id=$contactId sequential=0} {foreach from=$result.values item=contact name=outer_loop}        Name: {$contact.display_name}</br>     Contact Type: {$contact.contact_type}</br>     Sub Contact Type: {foreach from=$contact.contact_sub_type item=sub name=inner_loop}{$sub}, {foreachelse}<i>Nothing to see here</i>{/foreach} {/foreach}  
  > **username_1**: That looks ok. You can use `{debug}` after the crmAPI call to pop up a box that will show you what smarty thinks the variables are.  
  > **username_0**: Thanks!!! Duh, the $ContactId I was testing on did not have a sub_type so of course it was not turning up any results. Once I saw the debug was empty I realized my error.  
  > **username_0**: In case someone is looking for some code like this...{crmAPI var='result' entity='Contact' action='get' id=$contactId sequential=0} {debug} {foreach from=$result.values item=contact name=outer_loop}        {foreach from=$contact.contact_sub_type item=sub name=inner_loop}         {if $sub == 'Student'}                      {* Put in what you want to display for sub_types "Students" *}                  {/if}     {/foreach} {/foreach}  
  
  ---
  
  