Sign in

Building a persistent list of posts

  • This topic has 4 replies, 2 voices, and was last updated 1 year, 8 months ago by .
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
  • #4208

    Hey I’m modifying the Square theme to always display a list of all posts on the left hand side. This is going well so far, but I am confused about how to do something.

    I iterate over all posts via @website.contentStructure.posts and build the list and inside there am attempting to check if the currently iterated over post is the one that is being build from #post. This causes a syntax error when building in Publii. This is probably rooted in my misunderstanding of how the variables are scoped in Publii’s way of using Handlebars.

    <h1>All Posts</h1>

    {{/unless}} {{/each}}



    What would be the right way to do this?



    Try this way:

       <h1>All Posts</h1>
         {{#each @website.contentStructure.posts}} 
               <a href="{{url}}" rel="nofollow"> <strong>{{title}}</strong> </a>


    Do you appreciate the support you've received today? If so, consider donating to the Publii team by clicking here; we'll be sure to use your donation to make Publii even better!


    Hey Bob,

    That’s what I’m doing. My question maybe was unclear. I’m trying to style the currently displayed post differently than the rest. The #checkif in my code is what’s trying to do that, and the // comment is where that alternate styling would be. Other than that, my code is functionally the same as what you posted.


    Ultimately this is about the “evaluation context” in Handlebars. I’m trying to access the context of #post inside of an #each that changes the context to the iterated upon post. I’m not clear on if this is possible, and if it isn’t, what I would do instead.


    Ok I have a solution. It doesn’t work unless the site is deployed and URLs are real. Here it is:

    <br> <h1>All Posts</h1>

    Still, I’d like to understand if I can get at the current Post from inside an #each over the website’s posts. However, I’m all set with this problem.

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.