Himmators
Himmators

Reputation: 15006

Is it possible to create a single file for a collection?

I have a set of pages that are pretty similair, only a few attributes differ. In the collection docs it says I should create a single document for every item, like this:

_my_collection/
└── some_doc.md
└── more_doc.md

but that is not very convinient, I would rather create a single yaml-file with all the content in it:

my_collection.yaml

my_collection:
   some_doc:
      attribute_1: foo
      attribute_2: bar
   more_doc:
      attribute_1: foo
      attribute_2: bar

Is this at all possible?

Upvotes: 1

Views: 235

Answers (2)

TBB
TBB

Reputation: 1227

UPDATED FOLLOWING QUESTION CLARIFICATION:

Not if you want to output pages. The file is the trigger to build a page. Except, as you point out, with a plugin/extension - which will not work on github.

Yes, if you are just referencing the values. Use something like:

{{site.myCollection.collectionFile.some_doc.attribute_1}}

Although this is probably better done as a data file inside your _data folder with something like:

{{site.data.myDataFile.some_doc.attribute_1}}

You can loop through values too in a file too - though be aware about how hash and arrays differ when you structure your file.

Upvotes: 1

Himmators
Himmators

Reputation: 15006

I ended up using a really neat extension called data_page_generator

it can make pages out of yaml and csv and works out of the box.

Upvotes: 1

Related Questions