{{#has}}-helpers not working in pagination

Unfortunately I’m still having problems to get my pagination multilingual. My site is maintained in English and German and all English posts and pages are tagged with #en. In my handlebar templates I then use helpers like {{#has tag="#en"}}ENGLISH{{else}}GERMAN{{/has}} to render the correct language. This works everywhere - except in the pagination. Even if I put the helper at the very top of my pagination.hbs, it always renders “GERMAN”, even if I’m on the page tagged with #en.

This is my pagination.hbs that is included by using {{pagination}}, as suggested in the tutorial.

{{#page}}{{#has tag="#en"}}ENGLISH{{else}}GERMAN{{/has}}{{/page}}

<div class="pagination-container">
  {{#if prev}}
    <a href="{{page_url prev}}" class="previous">{{#page}}{{#has tag="#en"}}Newer posts{{else}}Neuere Beiträge{{/has}}{{/page}}</a>
  {{/if}}
  {{#if next}}
    <a href="{{page_url next}}" class="next">{{#page}}{{#has tag="#en"}}Older posts{{else}}Ältere Beiträge{{/has}}{{/page}}</a>
  {{/if}}
  <div class="clearfix"></div>
</div>

any help would be highly appreciated, I’m starting to get nuts :D

Which context are you in? I mean are you on an index page or somewhere? I’m trying to understand how the tag data is getting to your page :thinking:

Also, are you running Ghost locally? If you start your Ghost instance with ghost run -D, you can then debug more easily by using the {{log}} helper. In your case, you could add {{log this}} to your pagination file to see which data is available (it’ll be printed to the console).

Hey, thanks for your reply :blush: I have a custom template blog.hbs that I configured in my routes like this:

  /blog/:
    data: page.blog
    controller: channel
    filter: tag:-hash-en+tag:-hash-job-posting
    template: blog
  /blog-en/:
    data: page.blog-en
    controller: channel
    filter: tag:hash-en+tag:-hash-job-posting
    template: blog

and in my blog.hbs I render a bunch of posts like this:

  {{#foreach posts}}
    {{> "post-excerpt"}}
  {{/foreach}}

  {{pagination}} 

Thanks for the tip with the debugging! And you’re right - the problem seems to be, that the whole page{}-object that should include the tags is missing. The page with the /blog-en/ URL exists in my ghost admin. Am I doing something wrong in my routes configuration? :thinking:

Okay, I just discovered something else: when I put the {{log this}} before my {{pagination}}, the page{}-object is filled as expected (with all my tags, slug and everything). When I put the logs after the pagination, it just ays page: 1. Maybe it’s a bug that page data and the pagination are using the same “page”-key and it’s overwritten as soon as I use the pagination?

If I understand what’s happening, I think there are two options:

  1. I’m not able to replicate your exact setup right now, but I think the context isn’t right. Are you able to go up a level like `{{log …/page}}?
  2. Pass data to pagination directly and use the match helper. This solution will be a bit more work, but it should work:

In your index page, set up the if statement for the different languages:

{{#has tag="#en"}}
  {{pagination lang="en"}}
{{else}}
  {{pagination lang="de"}}
{{/has}}

Then, in pagination, you’ll have the lang attribute available.

{{#match lang "en"}}
English version of pagination
{{else}}
German version of pagination
{{/match}}

Let me know how you get on!

thanks for your help :) I really appreciate it.

  1. I’m able to log {{log page}}, but only before the pagination. This is the output:
{
  slug: 'blog-en',
  id: '621e17c840c0cb78bc1af454',
  uuid: '99c16cef-67ed-4fa6-bcd5-b1685db234b1',
  title: 'Blog (EN)',
  html: '<p>Blog content</p>',
  comment_id: '620e5d1d3144a300012fa76e',
  feature_image: null,
  featured: false,
  visibility: 'public',
  created_at: '2022-02-17T14:35:09.000+00:00',
  updated_at: '2022-03-07T16:23:45.000+00:00',
  published_at: '2022-02-17T14:35:21.000+00:00',
  custom_excerpt: null,
  codeinjection_head: null,
  codeinjection_foot: null,
  custom_template: null,
  canonical_url: null,
  authors: [
    {
      id: '1',
      name: 'Alina N.',
      slug: 'alina',
      profile_image: '//www.gravatar.com/avatar/342e93ef2a19e805a2de0de4faccab4d?s=250&d=mm&r=x',
      cover_image: null,
      bio: null,
      website: null,
      location: null,
      facebook: null,
      twitter: null,
      meta_title: null,
      meta_description: null,
      url: 'http://localhost:2368/404/'
    }
  ],
  tags: [
    {
      id: '621e17c840c0cb78bc1af61e',
      name: '#en',
      slug: 'hash-en',
      description: null,
      feature_image: null,
      visibility: 'internal',
      og_image: null,
      og_title: null,
      og_description: null,
      twitter_image: null,
      twitter_title: null,
      twitter_description: null,
      meta_title: null,
      meta_description: null,
      codeinjection_head: null,
      codeinjection_foot: null,
      canonical_url: null,
      accent_color: null,
      url: 'http://localhost:2368/404/'
    },
    {
      id: '621e17c840c0cb78bc1af62e',
      name: '#translation-is-blog',
      slug: 'hash-translation-is-blog',
      description: null,
      feature_image: null,
      visibility: 'internal',
      og_image: null,
      og_title: null,
      og_description: null,
      twitter_image: null,
      twitter_title: null,
      twitter_description: null,
      meta_title: null,
      meta_description: null,
      codeinjection_head: null,
      codeinjection_foot: null,
      canonical_url: null,
      accent_color: null,
      url: 'http://localhost:2368/404/'
    }
  ],
  tiers: [
    {
      id: '6215245313d77af8968f1881',
      name: 'Free',
      slug: 'free',
      active: true,
      welcome_page_url: '/',
      monthly_price_id: null,
      yearly_price_id: null,
      description: null,
      type: 'free',
      created_at: 2022-02-22T17:58:43.000Z,
      updated_at: 2022-02-22T18:18:27.000Z,
      visibility: 'public'
    },
    {
      id: '6215245313d77af8968f1882',
      name: 'Default Product',
      slug: 'default-product',
      active: true,
      welcome_page_url: '/',
      monthly_price_id: null,
      yearly_price_id: null,
      description: null,
      type: 'paid',
      created_at: 2022-02-22T17:58:43.000Z,
      updated_at: 2022-02-22T17:58:43.000Z,
      visibility: 'none'
    }
  ],
  primary_author: {
    id: '1',
    name: 'Alina N.',
    slug: 'alina',
    profile_image: '//www.gravatar.com/avatar/342e93ef2a19e805a2de0de4faccab4d?s=250&d=mm&r=x',
    cover_image: null,
    bio: null,
    website: null,
    location: null,
    facebook: null,
    twitter: null,
    meta_title: null,
    meta_description: null,
    url: 'http://localhost:2368/404/'
  },
  primary_tag: null,
  url: 'http://localhost:2368/blog-en/',
  excerpt: 'Blog content',
  reading_time: 0,
  page: true,
  access: true,
  og_image: null,
  og_title: null,
  og_description: null,
  twitter_image: null,
  twitter_title: null,
  twitter_description: null,
  meta_title: null,
  meta_description: null,
  frontmatter: null,
  feature_image_alt: null,
  feature_image_caption: null,
  secure: false
}

If I try logging it after the pagination, nothing happens (also, {{#page}}{{content}}{{/page}} renders undefined when using it after the pagination)

  1. when adding the if-statement to my blog.hbs I get a 404-error. When adding it to the index.hbs the match helper won’t work, since I don’t use this template for my blog-page (so, always “German version of pagination” is printed).

So I’m starting to ask myself: is it even possible to use a foreach-post-loop + pagination on a custom template that is not index.hbs?

This sounds like a tricky case.

Is your repo public by any chance? Since there are so many variables at play, I think it’ll be difficult to ascertain exactly what’s possible and not here. :thinking: