Data files in the same directory as my source files?

I want to keep page-specific datafiles next to the source files which are going to use them, for clarity. So I want to end up with something like this:

_pages
  my-page
    index.md
    _data.yaml

…becoming:

_site
  my-page
    index.html

Then I’ll have a custom tag in the markdown file actually use the yaml file to generate text.

Is there any way to achieve this?

not that I know of, data files go in the _data folder.

Just remember that the whole philosophy of Jekyll is to have conventions to avoid configuration. So most of the time, you don’t have configuration options for that kind of things.

FWIW you can change the default data folder but it’s a global setting, there’s no per page settings.

data_dir:        _pages/my-page/

The trouble with ‘convention over configuration’ is that it completely falls down when faced with, e.g., the kind of external requirements I have here. I really can’t rearrange the source files.

I think I can work around this by creating a _data.yaml file, so that it’s ignored by the generator, and then manually loading it in Ruby code. It’s really ugly, but it at least lets me make progress.

What prevents you from having a script moving the yaml files in the _data folder?

1 Like

Nothing, of course, but it seems like a waste to add a whole other moving part for something which should be so simple…

If the data file is small, you could put it in the front matter.

@davidgiven I too see a need for data file next the the source files.

  1. All the source file in that same folder can make use of just one datafile, without front matter on each of the source file.
  2. Individual source file that need to overide the data can have individual front matter.

Will be perfect if the datafile can also be inherited from top-level folder(s)

@jpl and @davidgiven: I have the same need too. Have you figured out a neat solution?

This page structure works best for me because I can run Grammarly on _data.yaml and use Liquid features to access it at the same time.

_pages
  my-page
    index.html
    _data.yaml

Alternatively, is there a way to read a markdown list items iteratively using Liquid?

I honestly can’t even remember what this was about. Looking at my repo I only see one data file and it’s a global one, so does belong in the _data directory.

1 Like