eleventy
eleventy copied to clipboard
Tags from external API
Hey Friends,
I have been running into some issues with 11ty. The setup I am using is pretty strait forward. I have a google sheet setup for a product list. We have another service that turns it into an api that we call using "axios"
On the product list there is a tags section where we have added a tag for each product. I am able to call all other sets of data no problem but, I am unable to add the tags to the front matter using a data call.
Please see the code below. Is this even possible?
Products.njk
---
layout: layouts/base.njk
section: products
permalink: /products/index.html
tags: ['products', {{ product_list.tag }}]
---
<h1>{{ title }}</h1>
{% set postslist = products %}
{% include "components/products-postslist.njk" %}
products_list.js
const axios = require('axios');
module.exports = async () => {
const result = await axios.get('API_GOES_HERE');
return result.data.result.dataList;
};
products.md
---
pagination:
data: products_list
alias: products_list
size: 1
layout: layouts/products-data.njk
permalink: '/products/{{products_list.title|slug}}/'
---
related to https://github.com/11ty/eleventy/issues/1059
Hello, this is something we've been chewing our nails on for some time. Does anyone have any way to accomplish this?
Right now, we're having to introduce a build step that pulls a ton of content, creates JSON files, and then feeds that into the config because the config can't handle async requests. Then we create our collections there and do the rest, but I really should just be able to put "tags: myPostData.tags" or "tags: {{ myPostData.tags }}" or something and have it work.
What has to happen for this to work? Am I missing something simple?