Download
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.

Mercury theme filter help

  • #5341
    Avatar photo[anonymous]

    Good day to all and also to Bob, who is always answering to me and helping here. I need your help again.

    I like the way how mercury theme filtet is working. I don’t need it on main page (in index.hbs) so I decided to transfere this functional to another page. And, as I expected, it is not working. My steps:

    1. I created alternative post template post-portfolio.hbs
    2.
    In config.json I added

    "postTemplates": {
      "portfolio": "portfolio filter"
    },

    3. Created a post, hide it, exclude it from main page and chose post template “portfolio filter”
    4. In alternative post template post-portfolio.hbs I copied all from default index.hbs (where filters were).
    5. I created three tags, three posts. To each post I added a tag.

    Now, when I am entering …/preview/portfolio.html I see that head, navbar, footer are working. Then I can see that the first part of filter is showing (where navigation is) and then I see endless loading (circle) but no posts cards next after filter navigation. In dev tools in console there is no errors or warnings.

    What did I missed? Help me please.

    #5342
    Avatar photo[anonymous]

    here is a screenshot of page

    #5344
    Avatar photo[anonymous]

    I’m also testing out something similar.

    Replacing {{#each posts}} to {{#each @website.contentStructure.posts}} in the post template would show all the cards/posts like the front page.

    However, filtering did not work.  I think there may be some changes needed in the javascripts but I’m not there yet.

    #5351
    Avatar photo[anonymous]

    I looked at filter code in script tag in footer

    {{#checkIf @config.custom.frontSource '==' "default"}}

    next line is

    {{#is "index,tag,tags,author,post-portfolio"}}

    so I added “post-portfolio” there and after {{else}} , but it didn’t helped.

    Thanks for {{#each @website.contentStructure.posts}} – good idea on future))

    #5361
    Avatar photoBob

    The post-portfolio template is an alternate post template and refers to the post context, so copying the index content to the new post template just won’t work. The @shaun2k “trick” should help here.

    I don’t have much time now to check if everything works and provide you a complex solution, but from what I can see there is a wrong “is” helper argument, so maybe it will help you:

    instead of:

    {{#is "index,tag,tags,author,post-portfolio"}}
    

    use:

    {{#is "index,tag,tags,author,post"}}
    
    #5365
    Avatar photo[anonymous]

    Thanks @Bob for the suggested change to the “is” helper.

    The filtering part is working but hidden posts are also shown in the listing.

    How do we omit hidden posts when using {{#each @website.contentStructure.posts}} instead of {{#each posts}}?

    Thanks.

    #5366
    Avatar photo[anonymous]

    To add to my last post, I figured out how to omit posts that are marked as “hidden” or without any tag from the post listing by replacing

    {{#each posts}}
       <article

    with

    {{#each @website.contentStructure.posts}}
        {{#unless isHidden}}
            {{#if mainTag}} <!-- mainTag will be empty if the post has no tags -->
                <article
    
    

    Thanks to @Bob and @Yaroslav!

    #5376
    Avatar photo[anonymous]

    This is fantastic! Everything works just like I wanted)) Once again, thank you Bob, for helping us to learn Publii. Thank you shaun2k for sharing your great ideas and experience, it helped me a lot.