GetPublii / Publii

The most intuitive Static Site CMS designed for SEO-optimized and privacy-focused websites.
https://getpublii.com
GNU General Public License v3.0
6.06k stars 407 forks source link

[Feature Request]: Helper to display an array of Maintags #1329

Closed candidexmedia closed 4 months ago

candidexmedia commented 5 months ago

Feature Description

Hello! This feature request hopes to address the confusion surrounding the filter by Maintags function found in certain themes:

Many believe that filtering posts by their Maintag means that only Maintags will be displayed in the list of filters, but that isn't the case (or possible at the moment). My wish would be to have some kind of helper similar to #each tags, but for maintags (ie #each maintag).

dziudek commented 4 months ago

@candidexmedia - it will be available on v.0.45 as:

{{#each mainTags}}
...
{{/each}}

It will work like {{#each tags}}...{{/each}} but will be limited only to tags set as main tag :)

candidexmedia commented 4 months ago

Amazing, thank you!

candidexmedia commented 1 month ago

Hi @dziudek! Is it possible to exclude mainTags from an array, like:

{{if its a tag}}
 {{#each tag EXCEPT mainTags}}
...
{{/each}}
{{/if}}

or

{{getTags isNot mainTag}}
..

Ref: https://github.com/GetPublii/Publii/discussions/1504

dziudek commented 1 month ago

@candidexmedia - there is unfortunately no simple way.

The easiest solution would be creating a custom helper https://getpublii.com/dev/how-to-create-a-custom-helper/ which receives mainTags and ID of tag to check - something like:

mainTagChecker: function(mainTags, id) {
    return mainTags.some(tag => tag.id === id);
}

And then use it as:

{{#if tags}}
    {{#each tags}}
        {{#unless (mainTagsChecker mainTags this.id)}}
            <a href="{{url}}">{{name}}</a>
        {{/unless}}
    {{/each}}
{{/if}}

In Publii v.0.46 I will try to add some flag like "isMainTag" to the tags object

candidexmedia commented 1 month ago

Thank you for the help @dziudek!

cc: @3muchfun