Included more details about adding defaults to static files
Based on the functionality released in [3.4.2](http://jekyllrb.com/news/2017/03/09/jekyll-3-4-2-released/) re adding defaults to static files, I thought this page needed some more detail.
This commit is contained in:
parent
351e3abd8e
commit
f9243c5ab1
|
@ -65,3 +65,35 @@ following metadata:
|
|||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
Note that in the above table, `file` can be anything. It's simply an arbitrarily set variable used in your own logic (such as in a for loop). It isn't a global site or page variable.
|
||||
|
||||
## Add front matter to static files
|
||||
|
||||
Although you can't directly add front matter values to static files, you can actually set front matter values through the [defaults property](../configuration/#front-matter-defaults) in your configuration file. When Jekyll builds the site, it will use the front matter values you set.
|
||||
|
||||
Here's an example:
|
||||
|
||||
In your `_config.yml` file, add the following values to the `defaults` property:
|
||||
|
||||
```yaml
|
||||
defaults:
|
||||
- scope:
|
||||
path: "assets/img"
|
||||
values:
|
||||
image: true
|
||||
```
|
||||
|
||||
This assumes that your Jekyll site has a folder path of `assets/img` where you have images (static files) stored. When Jekyll builds the site, it will treat each image as if it had the front matter value of `image: true`.
|
||||
|
||||
Suppose you want to list all your image assets as contained in `assets/img`. You could use this for loop to look in the `static_files` object and get all static files that have this front matter property:
|
||||
|
||||
```liquid
|
||||
{% raw %}{% for myfile in site.static_files %}
|
||||
{% if myfile.image == true %}
|
||||
{{ myfile.path }}
|
||||
{% endif %}
|
||||
{% endfor %}{% endraw %}
|
||||
```
|
||||
|
||||
When you build your site, the output will list the path to each file that meets this front matter condition.
|
||||
|
|
Loading…
Reference in New Issue