Sign in
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.

“tags” content is being overwritten inside “{{#post}}” context

  • This topic has 0 replies, 1 voice, and was last updated 1 year, 3 months ago by Avatar photomgc8.
Viewing 1 post (of 1 total)
  • Author
  • #8770
    Avatar photomgc8

    I’ve been using the EasyBlog theme for one of the sites I’m working on, and one of the features I like is the “All Topics” partial which adds a list of tags at the bottom of the front page. I wanted to have this also on other pages, but in a smaller area next to the post.

    Expected behaviour: adding the {{> all-topics}} partial would display all the tags from the website

    Actual behaviour: adding {{> all-topics}} only displays the tags of the current post, or stays empty if it has none

    I tracked this to the {{#each tags}} code block within the partial. If this is used outside of the {{#post}} block, then it contains all the tags. If used inside of it, the post’s tags overwrite them!

    There doesn’t seem to be any solution to this using the Publii tools and provided helpers. I was able to work around with a bit of a kludge, but I’d rather not have to do that — I think the solution would be to have the main/root tags array be named something different so it doesn’t clash, or otherwise the {{#post}} one (though that will require more changes to templates). Could you look into fixing this?

    Until then, here is how to work around it in a pinch:

    1. Add a custom Handlebars helper in a helpers.js override file:
      • setVar: function (varName, varValue, options) {
             if (! {
        = {};
   [varName] = varValue;
    2. Save the tags before being overwritten by adding this bit at the very top of post{-boxed}.hbs, before {{#post}}:
      • {{setVar "alltags" tags}}
    3. Change the {{#each tags}} line wherever needed to be instead:
      • {{#each @root.alltags}}

    If there is any more information I can provide, just let me know.


Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.