Skip to main content

How do I insert line breaks with `if` or `foreach` statements in Smarty?

Note that any line breaks after the following tags will be removed when converted to HTML:

  • {if}
  • {/if}
  • {else}
  • {elseif}
  • {foreach}
  • {/foreach}
  • {section}
  • {/section}

With line breaks

The example below shows the syntax for inserting a line break with an if statement:

sample code
{if true} [line break]
Example 1 [line break]
{else} [line break]
This line is not displayed [line break]
{/if} [line break]
Sample text
sample display
Example 1 [line break]
Sample text

Without line breaks

This example shows the syntax without line breaks:

sample code
{if true}Example 2 {else}This line is not displayed {/if}
Sample text
sample display
Example 2 Sample text  

Support

If you have any other questions, please contact us or check out Our Slack Community.