admin管理员组文章数量:1220791
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 liquid tag is {% for post in site.posts %}
. I want to learn if there is a way to access the variable site.posts
from javascript, so that I can listen to the click event and dynamically filter the post. If not, what should I do?
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 liquid tag is {% for post in site.posts %}
. I want to learn if there is a way to access the variable site.posts
from javascript, so that I can listen to the click event and dynamically filter the post. If not, what should I do?
1 Answer
Reset to default 21You 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 jsonify
filter for any hash or array
---
---
{{ site.posts | jsonify }}
Old answer
---
---
{% capture posts %}
[
{% for post in site.posts %}
{
"title" : "{{ post.title }}",
"url" : "{{ post.url }}",
"date" : "{{ post.date | date: "%B %d, %Y" }}",
"content" : "{{ post.content | escape }}"
} {% if forloop.last %}{% else %},{% endif %}
{% endfor %}
]
{% endcapture %}
var posts = {{posts | strip_newlines}}
This will put the site.posts
objects collection in a json
form and attribute them to you javascript posts
var.
本文标签: Jekyll liquid tag inside javascriptStack Overflow
版权声明:本文标题:Jekyll: liquid tag inside javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1739261088a2155370.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论