[CS2] Template Formatting

Normally templates will be specified using double braces like this:

{{ 1 + 1 }}

However, there are other ways to format templates in Component.Studio 2.

Code Blocks

Normally you'd format an if condition like this:

{{ 'red' if british else 'blue' }}

However, you can also format it as a block if you have a lot of text to display or its a more complicated condition.

{% if british %}
red
{% elif brazillian %}
green
{% else %}
blue
{% endif %}

Notice that I also slipped in the elif command, which allows you to add a subsequent if condition.

Whitespace Control

Normally the template engine outputs everything outside of variable and tag blocks verbatim, with all the whitespace as it is in the file. Occasionally you don't want the extra whitespace, but you still want to format the template cleanly, which requires whitespace.

You can tell the engine to strip all leading or trailing whitespace by adding a minus sign ( -) to the start or end block or a variable.

{% if british -%} blue {%- endif %}<br>
	

The exact output of the above would be "blue". The  {%- strips the whitespace right before the tag, and -%} the strips the whitespace right after the tag.

And the same is for variables:  {{- will strip the whitespace before the variable, and -}} will strip the whitespace after the variable.

Comments

You can also add comments that are entirely unparsed.

{# this is a comment #}
Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us