Display mainTag in post template
-
September 5, 2022 at 8:20 pm #8245[anonymous]
Hello!
I’m editing the post.hbs and want the mainTag to appear on my posts if the post has one.
I’ve tried the following code, but it’s not working:
{{#checkIfAny mainTag}}
{{/checkIfAny}}
September 6, 2022 at 6:04 am #8247BobIt should work, so maybe the context is wrong.
{{#post}} {{#if mainTag}} <a href="{{mainTag.url}}" rel="nofollow">{{mainTag.name}}</a> {{/if}} {{/post}}
September 6, 2022 at 3:57 pm #8271[anonymous]Hi,
that sounds interesting.
The documentation states “{{mainTag}} – tag item selected as a main tag of a specific post.“, but where do I set a tag as main tag in the App?
I did not find a hint neither here: https://getpublii.com/docs/tags.html nor here: https://getpublii.com/dev/post-tags/
Thanks, Michael
September 6, 2022 at 3:59 pm #8272BobSeptember 6, 2022 at 4:00 pm #8275[anonymous][anonymous] wrote:Quote
I’ve tried the code exactly as you’ve laid it out, and it unfortunately doesn’t work… The main tag (in the post I’m testing out) is set / isn’T empty.
I’ll add my file in the next reply (privately). I’m using the Mercury theme.
September 6, 2022 at 4:01 pm #8276[anonymous]ok, got it. I have to set two or more tags … Thanks for the quick answer 🙂
September 6, 2022 at 4:03 pm #8277[anonymous]This reply has been marked as private.September 6, 2022 at 4:06 pm #8279Bob[anonymous] wrote:I’ll add my file in the next reply (privately). I’m using the Mercury theme.
Sorry mate, I’m too busy this week. Maybe the next.
September 6, 2022 at 4:07 pm #8280[anonymous]Hi, Bob,
just like candidexmedia I get no result with your snippet.
{{#each posts}} {{! loop that generates a list of posts }} <article class="post type-post status-publish format-standard hentry"><!-- .posts --><header class="post-header"> <h2 class="post-title"> {{! post title }} {{title}} {{! /post title }} </h2><!-- .post-inner --> </article><!-- .post --> {{/each}} {{! end loop of posts}}<span class="post-date"> {{! post creation date }} {{date createdAt 'DD. MMM YYYY'}} {{! /post creation date }} </span> <span> {{! post main tag }} {{#post}} {{#if mainTag}} {{mainTag.name}} {{/if}} {{/post}} {{! /post main tag }} </span><!-- .post-meta --> </header><!-- .post-header -->{{{text}}}<!-- .post-content -->September 6, 2022 at 4:08 pm #8281Bobmuch.fun wrote:just like candidexmedia I get no result with your snippet.
Play around with a theme that uses a main tag, e.g. Taste.
September 6, 2022 at 4:09 pm #8282[anonymous]ok, will do. Thanks again.
September 6, 2022 at 4:21 pm #8283BobSeptember 6, 2022 at 4:24 pm #8286[anonymous]does the index.hbs work with mainTag ?
September 6, 2022 at 4:25 pm #8287[anonymous][anonymous] wrote:PS: use the full site preview; Maintag is not displayed in the post preview.
Yes, that was the issue. I was checking in Post-Preview, and not full site preview. It’s working perfectly now, thank you Bob!
September 6, 2022 at 4:27 pm #8288[anonymous]much.fun wrote:does the index.hbs work with mainTag ?
It should. It’s used in the index.hbs of the Mercury theme (for the filter), and I assume it’s what’s being used in Technews for the tag icon above the titled in the home page (based on these release notes)
September 6, 2022 at 4:53 pm #8290[anonymous]ok, now my theme does it, too . Thanks for your help.