access to the collections object and json datas from javascript file with eleventy

  Kiến thức lập trình

I’m a very beginner in eleventy. And also in English !
I’m studying alone. I have an html page gallery.html with a dropdown menu. I have a javascript file that will add some html content dynamically depending on the item selected in the dropdown menu.
In the js file that is src/js I want to access to a collection object that I created in .eleventy.js named portraits. But i don’t know how to to it.
In the js if I write collections.portraits, if I start, collections object is not known.

I also want to access from this js file to datas in json files. these datas are in src/_data/photos.json. If I write photos.aKey in the js, if i start 11th server, photos is not defined.

How can i access to these datas from my js file ?

js calling json datas
if i start 11th server, and launch localhost, i have in the console : photos is not defined.
ReferenceError: photos is not defined

js using the collections object created in .eleventy.js
ReferenceError: collections is not defined

New contributor

Gaëlle Bono is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website Kho Theme wordpress Kho Theme WP Theme WP

LEAVE A COMMENT