We're evolving to serve you better! This current forum has transitioned to read-only mode. For new discussions, support, and engagement, we've moved to GitHub Discussions.

Building a persistent list of posts

  • #4208
    Avatar photo[anonymous]

    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?


    Avatar photoBob

    Try this way:

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

    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.

    Avatar photo[anonymous]

    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.

    Avatar photo[anonymous]

    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.