About FORLearn how the FOR command loops through arrays to repeat content in templates.Sep 25, 2025Knowledge
InformationArticle BodyOverview The FOR template command repeats content for each item in an array. Use FOR/END-FOR to loop through records and insert fields, build tables, or generate complex layouts across templates. Key Functionalities Iterate over any array or list.Access fields on the current item with $variable.Nest loops and apply JavaScript expressions for filtering. Syntax {# FOR item IN items #} {# $item.Field #}{# END-FOR item #} Examples Example 1: Loop to Display Text in Different Lines Suppose you have a list of opportunities related to an account, each with a unique name. You can use the FOR/END-FOR command to loop through this list and display each opportunity's name on its own line. {# FOR opp IN Account.Opportunities #}{# $opp.Name #}{# END-FOR opp #} The output for this command would be: Opportunity1Opportunity2Opportunity3Opportunity4 Example 2: Loop to Display a Row in a Table for Each Record Generate a table that lists each opportunity's name, stage, and amount. {# FOR opp IN Account.Opportunities #}<tr> <td>{# $opp.Name #}</td> <td>{# $opp.StageName #}</td> <td>{# c($opp.Amount) #}</td></tr>{# END-FOR opp #} The output for these commands would look like: <tr><td>OpportunityName1</td><td>Prospecting</td><td>$1.00</td></tr><tr><td>OpportunityName2</td><td>Closed Won</td><td>$2.00</td></tr><tr><td>OpportunityName3</td><td>Closed Lost</td><td>$3.00</td></tr> Example 3: Nested For Loops If your data structure involves an account with opportunities, and each opportunity has line items (OLIs), you can nest FOR/END-FOR commands to access the line items for each opportunity. {# FOR opp IN Account.Opportunity #}{# FOR lineItem IN $opp.OLIs #}{# c($lineItem.TotalPrice) #}{# END-FOR lineItem #}{# END-FOR opp #} The output of these commands would look like this: $1.00$2.00$3.00$4.00$5.00 Example 4: Filtering in a For Loop Use JavaScript to filter an array so that only opportunities with an amount greater than 5000 are displayed. {# FOR opp IN Account.Opportunities.filter(opp => opp.Amount > 5000) #}{# $opp.Amount #}{# END-FOR opp #} The output of these commands would look like this: 5001500210000 Notes Lines containing FOR or END-FOR are removed from the output.Place content you want to repeat between the FOR and END-FOR tags.Use $ before the loop variable to access its fields. Conclusion FOR loops let you generate dynamic content across Word, Excel, and PowerPoint templates. Next Steps FOR in Word FOR in Excel FOR in PowerPoint TitleAbout FORURL NameAbout-FOR