Removed erroneous liquid code, added back spacing

- removed erroneous liquid code with conditional include parameters
- added back spacing in {{ }} tags
This commit is contained in:
Tom Johnson 2016-12-27 21:39:56 -08:00 committed by Frank Taillandier
parent 56a7038a7e
commit acff6cd269
1 changed files with 17 additions and 35 deletions

View File

@ -70,7 +70,7 @@ The value of `content` (which is `This is my sample note`) will be inserted into
Passing parameters to includes is especially helpful when you want to hide away complex formatting from your Markdown content.
For example, suppose you have a special image syntax with complex formatting, and you don't want your authors to remember the complex formatting. As a result, you decide to simplify the formatting by using an include with parameters. Here's an example of the special image syntax you want to populate with an include:
For example, suppose you have a special image syntax with complex formatting, and you don't want your authors to remember the complex formatting. As a result, you decide to simplify the formatting by using an include with parameters. Here's an example of the special image syntax you might want to populate with an include:
```html
<figure>
@ -100,22 +100,6 @@ This include contains 5 parameters:
* `alt`
* `caption`
You could also use `if` tags to safeguard scenarios where either the parameter is optional or where the author doesn't include the parameter:
```liquid
{% raw %}<figure>
{% if {{include.url}} %}<a href="{{include.url}}">{% endif %}
<img src="{{include.file}}" {% if {{include.max-width}} %}
style="max-width: {{include.max-width}}" {% endif %}
alt="{{include.alt}}" />{% if {{include.url}} %}</a>{% endif %}
{% if {{include.caption}} %}
<figcaption>{{include.caption}}</figcaption>
{% endif %}
</figure>{% endraw %}
```
In this example, `{% raw %}if {{include.url}}{% endraw %}` will include the `url` only if the `url` parameter is specified in the include. You could also create default values using [Liquid's default filter](https://help.shopify.com/themes/liquid/filters/additional-filters#default).
Here's an example that passes all the parameters to this include (the include file is named `image.html`):
```liquid
@ -126,11 +110,9 @@ caption="This is the Jekyll logo." %} {% endraw %}
The result is the original HTML code shown earlier.
You can create includes that act as templates for a variety of uses &mdash; inserting audio or video clips, alerts, special formatting, and more.
To safeguard situations where users don't supply a value for the parameter, you can use [Liquid's default filter](https://help.shopify.com/themes/liquid/filters/additional-filters#default).
However, note that you should avoid using too many includes, as this will slow down the build time of your site. For example, don't use includes every time you insert an image. (The above technique shows a use case for special images.)
Additionally, if you have a include variable inside an `if` statement, such as `{% raw %}{% if {{include.url}} %}{% endraw %}`, don't use spaces inside the curly braces. For example, avoid this syntax: `{% raw %}{% if {{ include.url }} %}{% endraw %}`. Liquid will consider this extra spacing an error. (Outside of `if` statements, the spacing for include variables doesn't matter.)
Overall, you can create includes that act as templates for a variety of uses &mdash; inserting audio or video clips, alerts, special formatting, and more. However, note that you should avoid using too many includes, as this will slow down the build time of your site. For example, don't use includes every time you insert an image. (The above technique shows a use case for special images.)
### Passing parameter variables to includes
@ -183,4 +165,4 @@ Now when you insert the `spotlight.html` include file, you can submit the YAML f
{% raw %}{% include spotlight.html participants=site.data.profiles %}{% endraw %}
```
In this instance, `site.data.profiles` gets inserted in place of {% raw %}`{{include.participants}}`{% endraw %} in the include, and the Liquid logic processes. The result will be `Jane Doe`.
In this instance, `site.data.profiles` gets inserted in place of {% raw %}`{{ include.participants }}`{% endraw %} in the include file, and the Liquid logic processes. The result will be `Jane Doe`.