Hello everyone!
I’m trying to put together a Jekyll website which has automotive objects of Makes and Models, which I think means I need to have nested collections.
For this, I started by having this structured data folder system:
_data
_makes
audi.md
citroen.md
...
_models
berlingo.md
c1.md
c3.md
c3-aircross.md
c4.md
c4-aircross.md
...
Here’s how my citroen.md
looks like:
---
title: Citroen
slug: citroen
description: "Citroen cars offer something different to most rivals with a focus on innovative design, excellent comfort and superb value for money. We have a range of high-quality used Citroen cars for you to purchase or finance, including the C3, C4 Cactus and C1."
popular: true
---
Here’s how my c3.md
looks like, with a property called make
that I’m using to try and create the relationship between the two objects:
---
title: C3
slug: c3
description: "The Citroen C3 is a hatchback that's inexpensive to run and comfortable to drive. Its interior is colourful, quirky and feels well made. It also has a bigger boot than many key rivals."
popular: true
make: citroen
---
Not sure if this is the best way to do this, but it’s kind of working because I can list all of a make’s models like this:
{% assign makeModels = site.models | where: 'make', make.slug %}
{% for model in makeModels %}
<a href="{{ model.url }}">{{ model.title }}</a>
{% endfor %}
Also, collections on my _config.yml
look like this:
collections_dir: _data
collections:
makes:
output: true
permalink: /:collection/:name
models:
output: true
permalink: /makes/:make/:collection/:name
defaults:
- scope:
path: ""
type: "makes"
values:
layout: "make"
- scope:
path: ""
type: "models"
values:
layout: "model"
- scope:
path: ""
values:
layout: "default"
and that’s when things stop working because apparently I can’t do this:
permalink: /makes/:make/:collection/:name
because it’s throwing this error:
Liquid Exception: The URL template doesn't have make keys. Check your permalink template! in _layouts/make.html
What I want do is make sure that I have the list of makes on this permalink:
/makes/
the page for a particular make (e.g. Citroen) on this permalink:
/make/citroen
the page for a particular model (e.g. C3) as a child of that make, like so:
/make/citroen/model/c3
I’m aware that the problem looks like it’s that :make
in the permalink, but how could I have the make in the parmalink then? Help?