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']}
<div> Visible fields var: {$visible-fields} </div>

{if $group.title|in_array:$visible-fields}
  <table class ="report-layout">
  {foreach from=$group.values item=row}
      <th class="label">{$row.label}</td>
      <td class="crm-case-report-custom-field">{$row.value}</td>

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 <div> Visible fields var: {$visible-fields} </div> 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?


This method works for me:

{assign var=visible_fields value=','|explode:'value1,value2'}
<div>Visible fields var:
  {foreach from=$visible_fields item=foo}
    <div>Element is {$foo}</div>
  • Thank you. It was really the dash that broke the code... – emma Oct 1 '20 at 13:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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