Bigcommerce Stencil - Display Blog Posts on Homepa

2019-09-01 11:27发布

问题:

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.



标签: bigcommerce