Display mainTag in post template
- This topic has 15 replies, 3 voices, and was last updated 1 year ago by .
-
AuthorPosts
-
September 5, 2022 at 8:20 pm #8245
candidexmedia
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 #8247Bob
It should work, so maybe the context is wrong.
{{#post}} {{#if mainTag}} <a href="{{mainTag.url}}" rel="nofollow">{{mainTag.name}}</a> {{/if}} {{/post}}
--
Do you appreciate the support you've received today? If so, consider donating to the Publii team by clicking here; we'll be sure to use your donation to make Publii even better!September 6, 2022 at 3:57 pm #8271much.fun
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 #8272Bob
More details: https://getpublii.com/docs/adding-editing-and-deleting-posts.html#creatingyourfirstpost
--
Do you appreciate the support you've received today? If so, consider donating to the Publii team by clicking here; we'll be sure to use your donation to make Publii even better!September 6, 2022 at 4:00 pm #8275candidexmedia
Bob 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 #8276much.fun
ok, got it. I have to set two or more tags … Thanks for the quick answer 🙂
September 6, 2022 at 4:03 pm #8277candidexmedia
This reply has been marked as private.September 6, 2022 at 4:06 pm #8279Bob
candidexmedia 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.
--
Do you appreciate the support you've received today? If so, consider donating to the Publii team by clicking here; we'll be sure to use your donation to make Publii even better!September 6, 2022 at 4:07 pm #8280much.fun
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 #8281Bob
much.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.
--
Do you appreciate the support you've received today? If so, consider donating to the Publii team by clicking here; we'll be sure to use your donation to make Publii even better!September 6, 2022 at 4:09 pm #8282much.fun
ok, will do. Thanks again.
September 6, 2022 at 4:21 pm #8283Bob
candidexmedia wrote:I’ll add my file in the next reply (privately). I’m using the Mercury theme.
It was only one file, so I checked it now, and it works very well for me:
PS: use the full site preview; Maintag is not displayed in the post preview.
--
Do you appreciate the support you've received today? If so, consider donating to the Publii team by clicking here; we'll be sure to use your donation to make Publii even better!September 6, 2022 at 4:24 pm #8286much.fun
does the index.hbs work with mainTag ?
September 6, 2022 at 4:25 pm #8287candidexmedia
Bob 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 #8288candidexmedia
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 #8290much.fun
ok, now my theme does it, too . Thanks for your help.
-
AuthorPosts
- You must be logged in to reply to this topic.