Use Loop Tags In Template Messages

Both API message tags and loop tags can be used in the body of template messages. Depending on the type of block you are editing, there are certain limitations present when using loop tags in HTML tables.

Tip: While using loop tags in templates is possible, there are certain limitations that must be taken into consideration. For the best results, we suggest using loop tags in an HTML message. For more information on creating HTML messages, see Creating an Email Message Using the WYSIWYG Editor and Creating Email: HTML Code Editor.
  • If you are editing a block using the WYSIWYG editor, loop tags cannot be placed within an HTML element. For example:
    
    
    <table border="1px">
    	<tbody>
    		<tr>
    			<th>Product Name</th>
    			<th>Product Price</th>
    		</tr>
    		{dynamic_code}
    		{loop}
    		<tr>
    			<td>%%#productname_#%%</td>
    			<td>%%#productprice_#%%</td>
    		</tr>
    		{/loop}
    		{/dynamic_code}
    	</tbody>
    </table>
    
    					
    Notice the loop tags are contained within the table and tbody HTML elements.
    Tip: In the example above, notice how the dynamic code and loop tags have been placed inside of an HTML table. This was done so the content brought in via the loop tags will display nicely in a table. It is perfectly OK to do this, but you will need to TURN OFF the WYSIWYG editor (as is the case above) when working with dynamic code and HTML. The WYSIWYG editor attempts to correct what it sees as mistakes in HTML and will thus produce unintended results if it encounters dynamic code embedded in HTML. To turn off the WYSIWYG editor, click WYSIWYG Editor Off next to the Subject Line text box.
    You can still use loop tags in template blocks that use the WYSIWYG editor, just not loop tags contained inside of HTML elements. The following will work as expected:
    
    
    <p>Some Content</p>
    	{dynamic_code}
    	{loop}
    		%%#productname_#%%
    		%%#productprice_#%%
    	{/loop}
    	{/dynamic_code}
    <p>Some More Content</p>
    
    					
  • If you are editing a template block using a plain large text box, loop tags can be placed within the table HTML elements, however formatting issues arise if you attempt to add a border property to the table. For example: Template Loop Tag Table Border We suggest removing the border attribute from the table element:
    
    
    <table>
    	<tbody>
    		<tr>
    			<th>Product Name</th>
    			<th>Product Price</th>
    		</tr>
    		{dynamic_code}
    		{loop}
    		<tr>
    			<td>%%#productname_#%%</td>
    			<td>%%#productprice_#%%</td>
    		</tr>
    		{/loop}
    		{/dynamic_code}
    	</tbody>
    </table>
    
    					
    Template Loop Tag Table No Border
Tip: For more information on using loop tags, see API Loop Tags.
Tip: For more information on using API message tags, see API Message Tags.