--- title: Collections permalink: /docs/collections/ --- Not everything is a post or a page. Maybe you want to document the various methods in your open source project, members of a team, or talks at a conference. Collections allow you to define a new type of document that behave like Pages or Posts do normally, but also have their own unique properties and namespace. ## Using Collections To start using collections, follow these 3 steps: * [Step 1: Tell Jekyll to read in your collection](#step1) * [Step 2: Add your content](#step2) * [Step 3: Optionally render your collection's documents into independent files](#step3) ### Step 1: Tell Jekyll to read in your collection {#step1} Add the following to your site's `_config.yml` file, replacing `my_collection` with the name of your collection: ```yaml collections: - my_collection ``` You can optionally specify metadata for your collection in the configuration: ```yaml collections: my_collection: foo: bar ``` Default attributes can also be set for a collection: ```yaml defaults: - scope: path: "" type: my_collection values: layout: page ```
From v3.7.0
you can optionally specify a directory to store all your collections in the same place with collections_dir: my_collections
Then Jekyll will look in my_collections/_books
for the books
collection, and
in my_collections/_recipes
for the recipes
collection.
The folder must be named identically to the collection you defined in
your _config.yml
file, with the addition of the preceding _
character.
Files in collections that do not have front matter are treated as static files and simply copied to their output location without processing.
Variable | Description |
---|---|
|
Label of the containing collection. |
|
Path to the document relative to the collection's directory. |
|
The document's base filename, with every sequence of spaces and non-alphanumeric characters replaced by a hyphen. |
|
The |
|
Extension of the output file. (Included by default and usually unnecessary.) |
Variable | Description |
---|---|
|
The name of your collection, e.g. |
|
An array of documents. |
|
An array of static files in the collection. |
|
The path to the collection's source directory, relative to the site source. |
|
The full path to the collections's source directory. |
|
Whether the collection's documents will be output as individual files. |
In addition to any collections you create yourself, the
posts
collection is hard-coded into Jekyll. It exists whether
you have a _posts
directory or not. This is something to note
when iterating through site.collections
as you may need to
filter it out.
You may wish to use filters to find your collection:
{% raw %}{{ site.collections | where: "label", "myCollection" | first }}{% endraw %}
Variable | Description |
---|---|
|
The (unrendered) content of the document. If no YAML Front Matter is provided, Jekyll will not generate the file in your collection. If YAML Front Matter is used, then this is all the contents of the file after the terminating `---` of the front matter. |
|
The rendered output of the document, based on the
|
|
The full path to the document's source file. |
|
The path to the document's source file relative to the site source. |
|
The URL of the rendered collection. The file is only written to the destination when the collection to which it belongs has |
|
The name of the document's collection. |
|
The date of the document's collection. |
Performed by {{ album.artist }}{% if album.director %}, directed by {{ album.director }}{% endif %}
{% for work in album.works %}Composed by {{ work.composer }}