# If tag == name on post and tag page

**URL:** <https://forum.ghost.org/t/if-tag-name-on-post-and-tag-page/14671>\
**Category:** Themes\
**Created:** [May 26, 2020, 8:50am UTC](https://forum.ghost.org/t/if-tag-name-on-post-and-tag-page/14671 "2020-05-26T08:50:13Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Simbob](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/simbob/32/7940_2.png) [@Simbob](https://forum.ghost.org/u/Simbob)\
**Post date:** [May 26, 2020, 8:50am UTC](https://forum.ghost.org/t/if-tag-name-on-post-and-tag-page/14671/1 "2020-05-26T08:50:13Z")

</div>

Hi,

I have a sidebar which is shown on all pages. I would like to query if take == name and if so return something.

```
{{#is "tag, post"}}
    {{#tag}}
        {{#has slug="test"}}same content{{/has}}
    {{/tag}}
    {{#post}}
        {{#has tag="test"}}same content{{/has}}
    {{/post}}
{{/is}}

```

is there a smarter way to do this?

---

<div class="post-metadata">

**Author:** ![DavidDarnes](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/daviddarnes/32/3533_2.png) [@DavidDarnes](https://forum.ghost.org/u/DavidDarnes)\
**Post date:** [May 26, 2020, 4:20pm UTC](https://forum.ghost.org/t/if-tag-name-on-post-and-tag-page/14671/2 "2020-05-26T16:20:10Z")

</div>

Sorry but I’m a bit confused on your query and your code example. Are you trying to make a related posts area or something similar? Could you provide more context and info? Thanks!

---

<div class="post-metadata">

**Author:** ![Simbob](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/simbob/32/7940_2.png) [@Simbob](https://forum.ghost.org/u/Simbob)\
**Post date:** [May 27, 2020, 4:21am UTC](https://forum.ghost.org/t/if-tag-name-on-post-and-tag-page/14671/3 "2020-05-27T04:21:25Z")

</div>

I have a sidebar which is shown on all pages (tag, post, page etc). Now I would like to show an element in that sidebar if the `tag == something`. As example I have a post with tag `top news`. Now I would like to display the element in the sidebar if the user is on page `tag/top-news` or if the user is on a post having the tag `top-news`

---

<div class="post-metadata">

**Author:** ![DavidDarnes](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/daviddarnes/32/3533_2.png) [@DavidDarnes](https://forum.ghost.org/u/DavidDarnes)\
**Post date:** [May 28, 2020, 2:14pm UTC](https://forum.ghost.org/t/if-tag-name-on-post-and-tag-page/14671/4 "2020-05-28T14:14:30Z")

</div>

Thanks for providing more detail. I think you’re looking for the `#has` helper, which can check if a post has a certain tag:

> **[Ghost Handlebars Theme Helpers: has](https://ghost.org/docs/themes/helpers/has/)**
>
> \#has allows theme developers to ask questions about the current context and provides more flexibility ⚡️ Read more about custom Ghost themes!

Note that the use of this helper will need to be within the `#post` context so the tags related to the post can be read by the `#has` helper.

---

<div class="post-metadata">

**Author:** ![Simbob](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/simbob/32/7940_2.png) [@Simbob](https://forum.ghost.org/u/Simbob)\
**Post date:** [May 28, 2020, 2:40pm UTC](https://forum.ghost.org/t/if-tag-name-on-post-and-tag-page/14671/5 "2020-05-28T14:40:09Z")

</div>

Right, but what if I also would like to show my partial code on tag pages?

Thats why I provided this snippet to make it clear:

```
{{#is "tag, post"}}
    {{#tag}}
        {{#has slug="test"}}same content{{/has}}
    {{/tag}}
    {{#post}}
        {{#has tag="test"}}same content{{/has}}
    {{/post}}
{{/is}}

```

so on tag page with tag foo and on post with tag foo I have to show the same thing in the sidebar (which is shown on all pages)

---

<div class="post-metadata">

**Author:** ![DavidDarnes](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/daviddarnes/32/3533_2.png) [@DavidDarnes](https://forum.ghost.org/u/DavidDarnes)\
**Post date:** [May 28, 2020, 3:04pm UTC](https://forum.ghost.org/t/if-tag-name-on-post-and-tag-page/14671/6 "2020-05-28T15:04:57Z")

</div>

Ah I see yes. In that case maybe [blocks](https://ghost.org/docs/api/v3/handlebars-themes/helpers/block/) and [partials](https://ghost.org/docs/api/v3/handlebars-themes/helpers/partials/) would be useful to use here. blocks let you define and set areas of the template outside the context. Within your sidebar area you can set the following:

```auto
{{{block "sidebar-area"}}}

```

Then within your `tag.hbs` template:

```auto
{{#tag}}
  {{#has slug="test"}}
    {{#contentFor "sidebar-area"}}{{> sidebar-partial}}{{/contentFor}}
  {{/has}}
{{/tag}}

```

Finally, in your `post.hbs` template:

```auto
{{#post}}
  {{#has tag="test"}}
    {{#contentFor "sidebar-area"}}{{> sidebar-partial}}{{/contentFor}}
  {{/has}}
{{/post}}

```

The code within your `partials/sidebar-partial.hbs` would then be shown on the “test” tag page and any post with a tag of “test”. Does that help? Here’s some resource for reference:

> **[Ghost Handlebars Theme Helpers: block & contentFor](https://ghost.org/docs/themes/helpers/block/)**
>
> Create templates that inherit reusable templates with handlebars block and contentFor helpers. Read more about Ghost themes! 👻

> **[Ghost Handlebars Theme Helpers: partials](https://ghost.org/docs/themes/helpers/partials/)**
>
> Create reusable pieces of markup with Handlebars partials. Read more about Ghost themes! 👻
