Variables on tpl files

I need to concatenate a string into a variable name in a tpl file, I’ve tried it in many ways but without success, someone have any idea?

I would say concatenation is done simply by putting one following the other, without any special operator, but I am no expert on this.

The language is called “Smarty”, have you looked up Smarty tutorials?

Also, variables need to be assigned in PHP code before the Smarty template is rendered. Is your variable actually available inside the tpl, did you check?

Thnks for reply, i tried put one following the other but it didnt work, but i already solved the problem, usign an array and the operators math and assign to increment a variable and increase the index of the array with this variable

Ok, cool. Can you please share the exact code here? It might help someone in the future. Thanks.

Sure!!

  {assign var="i" value=1}
  {foreach from=$task_sales_stage item=item}
  <tr>
   </td>
  <td nowrap width="10%" scope="row">{$item}: </td>
	<td width="25%">
		<input type='text' name='task_sales_stage{$i}' size="3" value="{$task_sales_stageAr[$i]}">
		{math assign="i" equation="x + y" x=$i y=1}
  </td>
</tr>
{/foreach}
1 Like

Thanks!

But then, if I understand correctly, the real challenge you had to face here was to make a kind of loop, with one variable per item.

Actualy, first i tried to concatenate the name of the variable with a variable of the loop, but didnt work. Then i tried make the loop and update the index of the array. And this work for me!

In addition to this I want to compare the data returned from {{sugar_field parentFieldArray=‘fields’ vardef=$fields[$colData.field.name] displayType=‘DetailView’ displayParams=$colData.field.displayParams typeOverride=$colData.field.type}} in tab_panel_content.tpl file before displaying it. Please help me to resolve this.