Trying to remove titles for tagged posts

First off, apologies if this has been covered elsewhere but honestly I looked and didn’t find anything. Not sure if I was searching on the right thing.

Trying to remove titles for posts tagged with “micro”. Got this working easily in post.hbs.

I am trying to get it working in a “recent posts” section of my theme (Ubud from Aspire Themes). That starts with home.hbs which has a partial called recent_posts.hbs. recent_posts has a loop:

{{#foreach posts}}
{{> post-card }}

post_card.hbs does this:

  <div class='c-post-card__content'>
    <h2 class='c-post-card__title'>
      <a href='{{ url }}' class='c-post-card__url'>{{ title }}</a>
    <p class='c-post-card__excerpt'>{{ excerpt }}</p>

I’ve tried everything I can think of and cant seem to get the list of tags for the post in this spot. Tried {{#post}}{{/post}} and a few other things with no luck. In fact using #post makes the url AND the title disppear :joy: I thought the post context was being passed here because the theme author is accessing the url of the post and the title but if thats the case why am I not able to get the tag list? The test short posts I have are definitely tagged properly and the title disappears on the post.hbs page as noted.

Would be grateful for any help here. Really don’t understand what I’m doing wrong.

Have you tried wrapping the h2 with the {{has}} helper? I haven’t tried it, so there might be context limitations.

{{^has tag="micro"}}
    <h2 class='c-post-card__title'>
      <a href='{{ url }}' class='c-post-card__url'>{{ title }}</a>

Foreach should already have you in the post context. Can you work back up a bit from that foreach? I’m guessing there’s a #get request and if so, it needs to have include=“tags” or else you won’t have any tags to have available to that partial.

The other thing to check that that #has is weird. It wants the name of the tag, not the slug. So you want #micro, not hash-micro.
(I have no idea why that helper works that way, and I trip on it at least once a week.)

Ahh! Thanks Cathy - updated the snippet.

I’m assuming the block should be in the post context as well, but like you said there might be other variables :slight_smile:

Hey Vikas…thanks for the reply. Actually this is exactly what I’m doing in post.hbs where it works. Figured that would work in the other spot too but no luck.

Thanks Cathy. I will take a look!

That was it! The foreach was wrapped in a get. Had no idea that only the base data was included with that get and that other stuff had to be included. Of course that was in the documentation, I just didn’t read far enough… :roll_eyes:

Thank you so much!

And for anyone else who might venture in here looking for the same thing. Chris Hannah did the same thing on his blog. In his post he doesn’t talk about needing the include for the post page but he does discuss it with examples when talking about generating RSS feeds for the blog.

Relevant Ghost documentation is here: Ghost Handlebars Theme Helpers: get

specifically the part on include!