Access data file from template - data file is different for each product #2042
Unanswered
matijalasic
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
I'm building an 11ty website where I want to have multiple products and I want each product to have a its own .json file with all the product data. So, product_1 should have product_1.json file, product_2 should have product_2.json file, etc. All products have the same template. Data file name for each product is included in the .md file.
product_1.md file has basic info about the product, permalink, title, layout and the name of the data-file
--- layout: layouts/product.html permalink: "/product_1" title: "Product 1" data-file: "product_1" ---
In the template I want to access product information.
For example:
<h1>{{ product_1.name }}</h1>
This works and gives me product name only because I've used the specific file name (product_1) but this won't work for other products because it will always open this same product_1 file. I have to access
data-file
field from the product .md file but how do I do that?{{ data-file.name }}
doesn't work because it converts variable to string.Can anyone help with this?
Beta Was this translation helpful? Give feedback.
All reactions