-
|
I have a growing number of JSON files kept in a My goal is to make a series of posts, each featuring some introductory text and a list generated from one of my data files. Naturally, I would prefer to abstract as much as possible from this process. Ideally, I would like to only provide the name of each data file in each of my posts, and let the layouts do the work. I made a Now, I realize I could already make my post files like this: In fact, it works well and that's what I'm doing right now. However, this solution strikes me as somewhat clunky and inelegant (a repeatable pattern like this calls for some kind of abstraction instead of copy-pasting the code). I would much prefer to use a and only set the Putting I don't want to make my list using a shortcode instead of a partial, because my actual list is much more complicated than the simplified example provided here, and dealing with a long piece of HTML inside a JS string literal without the convenience of Nunjucks would become unmanageable. I also wouldn't like to merge my data files and store them in keys inside one large JSON (which would enable selecting them simply by a string declared in the front matter). I would be very grateful for any insight as to whether there is a proper Eleventy way of achieving my goal. If not, I will rest content with manually inserting partials into the post bodies. Thanks for your help anyway! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
You could try passing in a _data/sources filename from your template: ---
# src/possums.njk
layout: list-post
source: possums
title: Possums
---
<h1>{{ title }}</h1>---
# src/_includes/layouts/list-post.njk
layout: post
---
{{ content | safe }}
{%- set listdata = sources[source] -%}
{%- include "partials/list.njk" -%}OUTPUT<main>
<h1>Possums</h1>
<ul>
<li>the possum named Fluffy is 2 years old</li>
<li>the possum named Snugglepants is 5 years old</li>
</ul>
</main> |
Beta Was this translation helpful? Give feedback.
You could try passing in a _data/sources filename from your template:
OUTPUT