Tags helper returns link to /404 until restart


Issue Summary
When I create a new tag in the admin interface, the {{tags}} helper returns 404 as the {{url}} even though it’s setup in the admin interface correctly. This has been mentioned before here but not reported as a bug.

  • {{url}} to resolve to new tag url

Steps to Reproduce

  1. Use {{tags}} helper in default.hbs
  2. Add a new tag on the admin interface
  3. Add that tag to a post
  4. Load a page with {{tags}} in

Setup information

Ghost Version
5.128.0

Node.js Version
v20.19.3

How did you install Ghost?

  1. python venv,
  2. a nodeenv inside the venv,
  3. use npm to install ghost-cli@latest
  4. run ghost install local

Provide details of your host & operating system
Local development in WSL Ubuntu on Windows

Database type
SQLite 3

You’ll need to add a post to the tag − only then it becomes “populated” and has an URL.

Otherwise, you’d have empty tags in the sitemap – not great SEO.

There’s an older discussion on it on Github:

Different issue. I just double-checked and I’m sure of it. This happens with a post in the tag. If it doesn’t happen for you, perhaps it’s something to do with ghost install local?

Interesting.

Can you share the exact handlebar snippet you’re trying? Would like to see if I can replicate this.

I have this in index.hbs

{{#foreach tags}}
      {{#if @last}}
          <span>
              <a href="{{url}}">{{name}} ({{count.posts}})</a>
          </span>
      {{else}}
          <span>
              <a href="{{url}}">{{name}} ({{count.posts}})</a> &bull;
          </span>
      {{/if}}
{{/foreach}}

Any chance you’re updating tags using the bulk edit function from the list of posts, instead of on the individual posts? If so, that’s probably your problem. Ghost doesn’t update routing in response to bulk edit changes.

No (at least I don’t think so), I’m updating it from:

http://localhost:2368/ghost/#/tags

But if I create a new tag directly on the post then it works correctly.

Hang on… I’m confused. Are you changing the slug of the tag from /ghost/#/tags? Or something else? Creating a new tag from /ghost/#/tags wouldn’t apply it to any posts, so I’m missing something here.. .

I right clicked on it in what you presumably call the bulk editor, but I didn’t know it did bulk editing at the time so the penny only just dropped.

Right. My question was about how you added the tag to the posts?

I right clicked on it in what you presumably call the bulk editor, but I didn’t know it did bulk editing when I added the tag so the penny has only just dropped.

Ahha! Mystery solved, then! So, to get immediate updates, click into the post and add the tag there, instead of from the list of posts.

(I’ve got a bug open on it.)

Update: I think as long as you add the tag to one post using the post editor (not bulk edit), everything should behave correctly. It’s just that the difference between 0 posts with a tag and 1+ post with a tag changes the routing, and ghost doesn’t realize there are any posts with that tag unless at least one of them gets it via the post editor.

2 Likes