Updated to remove spacing from include variables
It turns out Liquid throws an error when you write `{% if {{ include.url }} %}` instead of `{% if {{include.url}} %}`. I updated the examples here to omit the spacing. To avoid inconsistency, I just omitted the spacing from all curly braces. Also added a note explaining the issue and put the blame on Liquid.
This commit is contained in:
parent
8289b61316
commit
56a7038a7e
|
@ -60,7 +60,7 @@ You can also pass parameters to an include. For example, suppose you have a file
|
|||
</div>{% endraw %}
|
||||
```
|
||||
|
||||
The `{% raw %}{{ include.content }}{% endraw %}` is a parameter gets populated when you call the include and specify a value for that parameter, like this:
|
||||
The `{% raw %}{{include.content}}{% endraw %}` is a parameter that gets populated when you call the include and specify a value for that parameter, like this:
|
||||
|
||||
```liquid
|
||||
{% raw %}{% include note.html content="This is my sample note." %} {% endraw %}
|
||||
|
@ -130,6 +130,8 @@ You can create includes that act as templates for a variety of uses — inse
|
|||
|
||||
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.)
|
||||
|
||||
### Passing parameter variables to includes
|
||||
|
||||
Suppose the parameter you want to pass to the include is a variable rather than a string. For example, you might be using {% raw %}`{{site.product_name}}`{% endraw %} to refer to every instance of your product rather than the actual hard-coded name. (In this case, your `_config.yml` file would have a key called `product_name` with a value of your product's name.)
|
||||
|
|
Loading…
Reference in New Issue