Bigcommerce Stencil - Display Blog Posts on Homepage

为君一笑 提交于 2019-12-12 02:44:00

问题


We're looking to display blog posts on the homepage using Stencil/Handlebars. So far, I've tried the code below to no avail:

<ul>
{{#each blog}}
<li><a href="{{url}}">{{title}}</a></li>
{{/each}}
</ul>

AND

<ul>
{{#each blog.post}}
<li><a href="{{url}}">{{title}}</a></li>
{{/each}}
</ul>

Is it possible that the Blog object is not available on the homepage? Seems a little silly not to be able to use the Blog object wherever I want...?

Thanks in advance!


回答1:


In order to ensure best performance, we do not load up all resources on each page by default. You can pull in the blog resource by using the frontmatter invocation defined here in the documentation https://stencil.bigcommerce.com/docs/front-matter-variables

At the top of your home.html you should have a section like this:

---
blog:
    recent_posts:
---

Once that exists you should be able to access the blog post data inside the rendering context.



来源:https://stackoverflow.com/questions/35414226/bigcommerce-stencil-display-blog-posts-on-homepage

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!