diff --git a/_basics/types.md b/_basics/types.md index ded1fd5..907caa3 100644 --- a/_basics/types.md +++ b/_basics/types.md @@ -95,9 +95,7 @@ To access all the items in an array, you can loop through each item in the array

Output

```text -{% raw %} Tobi Laura Tetsuro Adam -{% endraw %} ``` ### Accessing specific items in arrays diff --git a/_basics/whitespace.md b/_basics/whitespace.md index 337ea43..3dc8ec1 100644 --- a/_basics/whitespace.md +++ b/_basics/whitespace.md @@ -8,17 +8,17 @@ In Liquid, you can include a hyphen in your tag syntax `{% raw %}{{-{% endraw %} Normally, even if it doesn't output text, any line of Liquid in your template will still output a blank line in your rendered HTML:

Input

+```liquid {% raw %} -``` liquid {% assign my_variable = "tomato" %} {{ my_variable }} -``` {% endraw %} +``` Notice the blank line before "tomato" in the rendered template:

Output

-``` text +```text {% assign my_variable = "tomato" %} {{ my_variable }} ``` @@ -26,34 +26,34 @@ Notice the blank line before "tomato" in the rendered template: By including hyphens in your `assign` tag, you can strip the generated whitespace from the rendered template:

Input

+```liquid {% raw %} -``` liquid {%- assign my_variable = "tomato" -%} {{ my_variable }} -``` {% endraw %} +```

Output

-``` text +```text tomato ``` If you don't want any of your tags to output whitespace, as a general rule you can add hyphens to both sides of all your tags (`{% raw %}{%-{% endraw %}` and `{% raw %}-%}{% endraw %}`):

Input

+```liquid {% raw %} -``` liquid {% assign username = "John G. Chalmers-Smith" %} {% if username and username.size > 10 %} Wow, {{ username }}, you have a long name! {% else %} Hello there! {% endif %} -``` {% endraw %} +```

Output without whitespace control

-``` text +```text {% assign username = "John G. Chalmers-Smith" %} {% if username and username.size > 10 %} Wow, {{ username }}, you have a long name! @@ -63,18 +63,18 @@ If you don't want any of your tags to output whitespace, as a general rule you c ```

Input

+```liquid {% raw %} -``` liquid {%- assign username = "John G. Chalmers-Smith" -%} {%- if username and username.size > 10 -%} Wow, {{ username }}, you have a long name! {%- else -%} Hello there! {%- endif -%} -``` {% endraw %} +```

Output with whitespace control

-``` text +```text Wow, John G. Chalmers-Smith, you have a long name! ``` diff --git a/_filters/at_least.md b/_filters/at_least.md index 507eeb0..d7a43cd 100644 --- a/_filters/at_least.md +++ b/_filters/at_least.md @@ -6,11 +6,11 @@ description: Liquid filter that limits a number to a minimum value Limits a number to a minimum value.

Input

-{% raw %} ```liquid +{% raw %} {{ 4 | at_least: 5 }} -``` {% endraw %} +```

Output

``` @@ -18,11 +18,11 @@ Limits a number to a minimum value. ```

Input

-{% raw %} ```liquid +{% raw %} {{ 4 | at_least: 3 }} -``` {% endraw %} +```

Output

``` diff --git a/_filters/at_most.md b/_filters/at_most.md index 3871f7f..e05a7b4 100644 --- a/_filters/at_most.md +++ b/_filters/at_most.md @@ -6,11 +6,11 @@ description: Liquid filter that limits a number to a maximum value Limits a number to a maximum value.

Input

-{% raw %} ```liquid +{% raw %} {{ 4 | at_most: 5 }} -``` {% endraw %} +```

Output

``` @@ -18,11 +18,11 @@ Limits a number to a maximum value. ```

Input

-{% raw %} ```liquid +{% raw %} {{ 4 | at_most: 3 }} -``` {% endraw %} +```

Output

``` diff --git a/_filters/compact.md b/_filters/compact.md index 2c6f22b..1627318 100644 --- a/_filters/compact.md +++ b/_filters/compact.md @@ -8,15 +8,15 @@ Removes any `nil` values from an array. For this example, assume `site.pages` is an array of content pages for a website, and some of these pages have an attribute called `category` that specifies their content category. If we `map` those categories to an array, some of the array items might be `nil` if any pages do not have a `category` attribute.

Input

-{% raw %} ```liquid +{% raw %} {% assign site_categories = site.pages | map: 'category' %} {% for category in site_categories %} {{ category }} {% endfor %} -``` {% endraw %} +```

Output

```text @@ -32,15 +32,15 @@ For this example, assume `site.pages` is an array of content pages for a website By using `compact` when we create our `site_categories` array, we can remove all the `nil` values in the array.

Input

-{% raw %} ```liquid +{% raw %} {% assign site_categories = site.pages | map: 'category' | compact %} {% for category in site_categories %} {{ category }} {% endfor %} -``` {% endraw %} +```

Output

```text diff --git a/_filters/concat.md b/_filters/concat.md index 914e388..a41b604 100644 --- a/_filters/concat.md +++ b/_filters/concat.md @@ -6,8 +6,8 @@ description: Liquid filter that concatenates arrays. Concatenates (joins together) multiple arrays. The resulting array contains all the items from the input arrays.

Input

-{% raw %} ```liquid +{% raw %} {% assign fruits = "apples, oranges, peaches" | split: ", " %} {% assign vegetables = "carrots, turnips, potatoes" | split: ", " %} @@ -16,8 +16,8 @@ Concatenates (joins together) multiple arrays. The resulting array contains all {% for item in everything %} - {{ item }} {% endfor %} -``` {% endraw %} +```

Output

```text @@ -32,8 +32,8 @@ Concatenates (joins together) multiple arrays. The resulting array contains all You can string together `concat` filters to join more than two arrays:

Input

-{% raw %} ```liquid +{% raw %} {% assign furniture = "chairs, tables, shelves" | split: ", " %} {% assign everything = fruits | concat: vegetables | concat: furniture %} @@ -41,8 +41,8 @@ You can string together `concat` filters to join more than two arrays: {% for item in everything %} - {{ item }} {% endfor %} -``` {% endraw %} +```

Output

```text diff --git a/_filters/divided_by.md b/_filters/divided_by.md index 7099708..07842f2 100644 --- a/_filters/divided_by.md +++ b/_filters/divided_by.md @@ -8,26 +8,26 @@ Divides a number by the specified number. The result is rounded down to the nearest integer (that is, the [floor]({{ site.baseurl }}/filters/floor)) if the divisor is an integer.

Input

+```liquid {% raw %} -``` liquid {{ 16 | divided_by: 4 }} -``` {% endraw %} +```

Output

-``` text +```text {{ 16 | divided_by: 4 }} ```

Input

+```liquid {% raw %} -``` liquid {{ 5 | divided_by: 3 }} -``` {% endraw %} +```

Output

-``` text +```text {{ 5 | divided_by: 3 }} ``` @@ -38,28 +38,28 @@ The result is rounded down to the nearest integer (that is, the [floor]({{ site. For example, here the divisor is an integer:

Input

+```liquid {% raw %} -``` liquid {{ 20 | divided_by: 7 }} -``` {% endraw %} +```

Output

-``` text +```text {{ 20 | divided_by: 7 }} ``` Here it is a float:

Input

+```liquid {% raw %} -``` liquid {{ 20 | divided_by: 7.0 }} -``` {% endraw %} +```

Output

-``` text +```text {{ 20 | divided_by: 7.0 }} ``` @@ -70,15 +70,15 @@ You might want to use a variable as a divisor, in which case you can't simply ad In this example, we're dividing by a variable that contains an integer, so we get an integer:

Input

+```liquid {% raw %} -``` liquid {% assign my_integer = 7 %} {{ 20 | divided_by: my_integer }} -``` {% endraw %} +```

Output

-``` text +```text {% assign my_integer = 7 %} {{ 20 | divided_by: my_integer }} ``` @@ -86,16 +86,16 @@ In this example, we're dividing by a variable that contains an integer, so we ge Here, we [multiply]({{ site.baseurl}}/filters/times) the variable by `1.0` to get a float, then divide by the float instead:

Input

+```liquid {% raw %} -``` liquid {% assign my_integer = 7 %} {% assign my_float = my_integer | times: 1.0 %} {{ 20 | divided_by: my_float }} -``` {% endraw %} +```

Output

-``` text +```text {% assign my_integer = 7 %} {% assign my_float = my_integer | times: 1.0 %} {{ 20 | divided_by: my_float }} diff --git a/_filters/truncate.md b/_filters/truncate.md index 8103cb2..df502f4 100644 --- a/_filters/truncate.md +++ b/_filters/truncate.md @@ -24,14 +24,14 @@ description: Liquid filter that truncates a string to a given number of characte The length of the second parameter counts against the number of characters specified by the first parameter. For example, if you want to truncate a string to exactly 10 characters, and use a 3-character ellipsis, use **13** for the first parameter of `truncate`, since the ellipsis counts as 3 characters.

Input

+```liquid {% raw %} -``` liquid {{ "Ground control to Major Tom." | truncate: 25, ", and so on" }} -``` {% endraw %} +```

Output

-``` text +```text {{ "Ground control to Major Tom." | truncate: 25, ", and so on" }} ``` @@ -40,13 +40,13 @@ The length of the second parameter counts against the number of characters speci You can truncate to the exact number of characters specified by the first parameter and show no trailing characters by passing a blank string as the second parameter:

Input

+```liquid {% raw %} -``` liquid {{ "Ground control to Major Tom." | truncate: 20, "" }} -``` {% endraw %} +```

Output

-``` text +```text {{ "Ground control to Major Tom." | truncate: 20, "" }} ``` diff --git a/_filters/truncatewords.md b/_filters/truncatewords.md index 0a2d8ef..85e02e3 100644 --- a/_filters/truncatewords.md +++ b/_filters/truncatewords.md @@ -22,14 +22,14 @@ Shortens a string down to the number of words passed as the argument. If the spe `truncatewords` takes an optional second parameter that specifies the sequence of characters to be appended to the truncated string. By default this is an ellipsis (...), but you can specify a different sequence.

Input

+```liquid {% raw %} -``` liquid {{ "Ground control to Major Tom." | truncatewords: 3, "--" }} -``` {% endraw %} +```

Output

-``` text +```text {{ "Ground control to Major Tom." | truncatewords: 3, "--" }} ``` @@ -38,13 +38,13 @@ Shortens a string down to the number of words passed as the argument. If the spe You can avoid showing trailing characters by passing a blank string as the second parameter:

Input

+```liquid {% raw %} -``` liquid {{ "Ground control to Major Tom." | truncatewords: 3, "" }} -``` {% endraw %} +```

Output

-``` text +```text {{ "Ground control to Major Tom." | truncatewords: 3, "" }} ``` diff --git a/_filters/where.md b/_filters/where.md index 9d8becd..e036d42 100644 --- a/_filters/where.md +++ b/_filters/where.md @@ -8,8 +8,8 @@ Creates an array including only the objects with a given property value, or any In this example, assume you have a list of products and you want to show your kitchen products separately. Using `where`, you can create an array containing only the products that have a `"type"` of `"kitchen"`.

Input

-{% raw %} ```liquid +{% raw %} All products: {% for product in products %} - {{ product.title }} @@ -21,8 +21,8 @@ Kitchen products: {% for product in kitchen_products %} - {{ product.title }} {% endfor %} -``` {% endraw %} +```

Output

```text @@ -40,8 +40,8 @@ Kitchen products: Say instead you have a list of products and you only want to show those that are available to buy. You can `where` with a property name but no target value to include all products with a [truthy]({{ "/basics/truthy-and-falsy#truthy" | prepend: site.baseurl }}) `"available"` value.

Input

-{% raw %} ```liquid +{% raw %} All products: {% for product in products %} - {{ product.title }} @@ -53,8 +53,8 @@ Available products: {% for product in available_products %} - {{ product.title }} {% endfor %} -``` {% endraw %} +```

Output

```text @@ -71,13 +71,13 @@ Available products: The `where` filter can also be used to find a single object in an array when combined with the `first` filter. For example, say you want to show off the shirt in your new fall collection.

Input

-{% raw %} ```liquid +{% raw %} {% assign new_shirt = products | where: "type", "shirt" | first %} Featured product: {{ new_shirt.title }} -``` {% endraw %} +```

Output

```text