Skip to content Skip to sidebar Skip to footer

Jekyll: Liquid Tag Inside Javascript

Suppose I have two links: 'all posts' and 'personal.' When the user clicks the 'personal' link, he should only see the posts that have the category 'personal.' Right now, the liqui

Solution 1:

You can make Jekyll parse any file by adding an empty front matter to it.

example: assets/js/script.js

Edit 16/07/28 : you can use jsonifyfilter for any hash or array

------
{{ site.posts|jsonify }}

Old answer

------
{%captureposts%}
[
{%forpostinsite.posts%}
{
"title":"{{ post.title }}",
"url":"{{ post.url }}",
"date":"{{ post.date | date: "%B %d, %Y" }}",
"content":"{{ post.content | escape }}"
} {%ifforloop.last%}{%else%},{%endif%}
{%endfor%}
]
{%endcapture%}
varposts= {{posts|strip_newlines}}

This will put the site.posts objects collection in a json form and attribute them to you javascript posts var.

Post a Comment for "Jekyll: Liquid Tag Inside Javascript"