How to add counter variable in field-definition .tpl ?

Maybe the problem with your script is that it’s outputting the incremented number onto the produced HTML page? There are several solutions to this:

https://stackoverflow.com/questions/8674831/how-do-you-increment-an-assigned-variable-in-smarty-without-displaying-it

Somebody did this recently here in the SuiteCRM forums using arrays and math:

https://suitecrm.com/suitecrm/forum/suitecrm-7-0-discussion/27306-variables-on-tpl-files#88921