Get collection into javascript

Hi, I’m trying to get data from a page’s collection into Javascript (for use with a data-visualization library). Is there any elegant way to do this ?
Right now I’m doing something like this :

{% for child in collection %}

{% endfor %}

But this pollutes my page with many script tags.

You could use this grav plugin and then pull the data using AJAX.

I’m not sure what all you need, but I’ve used that plugin before for working with the page data and it works great.

Hi, what I need is to be able to get a page’s collection into a Javascript array of objects.
Say I have a page with a collection of blog posts. What I want is to be able to get into a JS script on this page an array of all the blog posts. It would look something like this :
[
{title: “Something”, date: “26-05-1968” …},
{…},

]

I though collections were PHP arrays so I tried to use json_encode(), but this returns an empty object.

Use the plugin I linked to above and you can return the page data as json.