mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-16 17:30:43 -07:00
Condense and improve examples
This commit is contained in:
+15
-9
@@ -23,19 +23,20 @@ Notice the blank line before "tomato" in the rendered template:
|
||||
{{ my_variable }}
|
||||
```
|
||||
|
||||
By including hyphens in your `assign` tag, you can strip the generated whitespace from the rendered template:
|
||||
By including a hyphen in your `assign` closing delimiter, you can strip the whitespace following it from the rendered template:
|
||||
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- assign my_variable = "tomato" -%}
|
||||
{% assign my_variable = "tomato" -%}
|
||||
{{ my_variable }}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
<p class="code-label">Output</p>
|
||||
```text
|
||||
tomato
|
||||
{% assign my_variable = "tomato" -%}
|
||||
{{ my_variable }}
|
||||
```
|
||||
|
||||
If you don't want any of your tags to print whitespace, as a general rule you can add hyphens to both sides of all your tags (`{% raw %}{%-{% endraw %}` and `{% raw %}-%}{% endraw %}`):
|
||||
@@ -45,7 +46,7 @@ If you don't want any of your tags to print whitespace, as a general rule you ca
|
||||
{% raw %}
|
||||
{% assign username = "John G. Chalmers-Smith" %}
|
||||
{% if username and username.size > 10 %}
|
||||
Wow, {{ username }}, you have a long name!
|
||||
Wow, {{ username }} , you have a long name!
|
||||
{% else %}
|
||||
Hello there!
|
||||
{% endif %}
|
||||
@@ -56,7 +57,7 @@ If you don't want any of your tags to print whitespace, as a general rule you ca
|
||||
```text
|
||||
{% assign username = "John G. Chalmers-Smith" %}
|
||||
{% if username and username.size > 10 %}
|
||||
Wow, {{ username }}, you have a long name!
|
||||
Wow, {{ username }} , you have a long name!
|
||||
{% else %}
|
||||
Hello there!
|
||||
{% endif %}
|
||||
@@ -65,16 +66,21 @@ If you don't want any of your tags to print whitespace, as a general rule you ca
|
||||
<p class="code-label">Input</p>
|
||||
```liquid
|
||||
{% raw %}
|
||||
{%- assign username = "John G. Chalmers-Smith" -%}
|
||||
{% assign username = "John G. Chalmers-Smith" -%}
|
||||
{%- if username and username.size > 10 -%}
|
||||
Wow, {{ username }}, you have a long name!
|
||||
Wow, {{ username -}} , you have a long name!
|
||||
{%- else -%}
|
||||
Hello there!
|
||||
{%- endif -%}
|
||||
{%- endif %}
|
||||
{% endraw %}
|
||||
```
|
||||
|
||||
<p class="code-label">Output with whitespace control</p>
|
||||
```text
|
||||
Wow, John G. Chalmers-Smith, you have a long name!
|
||||
{% assign username = "John G. Chalmers-Smith" -%}
|
||||
{%- if username and username.size > 10 -%}
|
||||
Wow, {{ username -}} , you have a long name!
|
||||
{%- else -%}
|
||||
Hello there!
|
||||
{%- endif %}
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user