Answers.Body: <p>This method works for me:</p>
  <pre><code>{assign var=visible_fields value=','|explode:'value1,value2'}
  &lt;div&gt;Visible fields var:
    {foreach from=$visible_fields item=foo}
      &lt;div&gt;Element is {$foo}&lt;/div&gt;
    {/foreach}
  &lt;/div&gt;
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-10-01T13:28:40.520Z
Answers.Text: Thank you. It was really the dash that broke the code...
Answers.UserDisplayName: emma
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-10-01T13:07:43.290Z
Answers.LastActivityDate: 2020-10-01T13:07:43.290Z
Answers.UserDisplayName: Demerit
Body: <p>I want to modify the  Smarty template sites/all/modules/civicrm/templates/CRM/Case/Audit/Report.tpl. I want to complement an existing foreach expression with comparing the incoming variable $group.title to an array of titles, and execute the following code only if the current $group.title is found in that array.</p>
  <pre><code>
  {assign var=visible-fields value=['value1, value2']}
  &lt;div&gt; Visible fields var: {$visible-fields} &lt;/div&gt;
  
  {if $group.title|in_array:$visible-fields}
    &lt;h2&gt;{$group.title}&lt;/h2&gt;
    &lt;table class =&quot;report-layout&quot;&gt;
    {foreach from=$group.values item=row}
        &lt;tr&gt;
        &lt;th class=&quot;label&quot;&gt;{$row.label}&lt;/td&gt;
        &lt;td class=&quot;crm-case-report-custom-field&quot;&gt;{$row.value}&lt;/td&gt;
        &lt;/tr&gt;
    {/foreach}
    &lt;/table&gt;
  {/if}
  
  </code></pre>
  <p>Now, I'm getting stuck on a rather simple task: The array <code>visible-fields</code> is not created. I have found some forum threads from the 2000s suggesting some expressions. I have tried the following, none of which seems to work:</p>
  <ul>
  <li><code>{assign var=visible-fields value=['value1, value2']}</code></li>
  <li><code>{assign var=visible-fields value=['value1', 'value2']}</code></li>
  <li><code>{assign var='visible-fields' value=['value1, value2']}</code></li>
  <li>and the same with &quot;&quot; instead of ''</li>
  <li><code>{assign var=&quot;visible-fields&quot; value=&quot;,&quot;|explode:['value1, value2']}</code></li>
  </ul>
  <p>Printing the variable with <code>&lt;div&gt; Visible fields var: {$visible-fields} &lt;/div&gt;</code>  results in a 0.</p>
  <p>I also tried solving the problem with a <code>{php}...{/php}</code> block, but then the web app throws an error. Maybe I have to enable the support for these inline php blocks somewhere, but before trying that, I want to try solving it with the Smarty expression, because creating an array shouldn't be so difficult, right?</p>
  <p>Can somebody tell me how to do it, or post a link?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-10-01T12:48:12.333Z
Comments.Text: Did you try with an underscore instead of dash, i.e. `$visible_fields`? I don't think smarty variables can have dashes: https://www.smarty.net/docsv2/en/language.syntax.variables.tpl
Comments.UserDisplayName: Demerit
Tags: <civicase><templates><smarty>
Title: Create array in Smarty template
ThreadText: # Create array in Smarty template
  
  (Asked by: username_0 on 2020-10-01)
  
  I want to modify the  Smarty template sites/all/modules/civicrm/templates/CRM/Case/Audit/Report.tpl. I want to complement an existing foreach expression with comparing the incoming variable $group.title to an array of titles, and execute the following code only if the current $group.title is found in that array.
  
  {assign var=visible-fields value=['value1, value2']}
   Visible fields var: {$visible-fields} 
  
  {if $group.title|in_array:$visible-fields}
    {$group.title}
    
    {foreach from=$group.values item=row}
        
        {$row.label}
        {$row.value}
        
    {/foreach}
    
  {/if}
  
  
  Now, I'm getting stuck on a rather simple task: The array visible-fields is not created. I have found some forum threads from the 2000s suggesting some expressions. I have tried the following, none of which seems to work:
  
  {assign var=visible-fields value=['value1, value2']}
  {assign var=visible-fields value=['value1', 'value2']}
  {assign var='visible-fields' value=['value1, value2']}
  and the same with "" instead of ''
  {assign var="visible-fields" value=","|explode:['value1, value2']}
  
  Printing the variable with  Visible fields var: {$visible-fields}   results in a 0.
  I also tried solving the problem with a {php}...{/php} block, but then the web app throws an error. Maybe I have to enable the support for these inline php blocks somewhere, but before trying that, I want to try solving it with the Smarty expression, because creating an array shouldn't be so difficult, right?
  Can somebody tell me how to do it, or post a link?
  
  **Tags:** civicase, templates, smarty
  
  > **Comments:**
  > **username_1**: Did you try with an underscore instead of dash, i.e. `$visible_fields`? I don't think smarty variables can have dashes: https://www.smarty.net/docsv2/en/language.syntax.variables.tpl  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-10-01. Score: 1 | Accepted answer
  
  This method works for me:
  {assign var=visible_fields value=','|explode:'value1,value2'}
  Visible fields var:
    {foreach from=$visible_fields item=foo}
      Element is {$foo}
    {/foreach}
  
  > **Comments:**
  > **username_0**: Thank you. It was really the dash that broke the code...  
  
  ---
  
  