Getting posts in blog feed to show fully if they're under a certain length

In my blog index, my goal is to show short posts (say, less than 500 words) in their entirety, but longer posts to offer a link to the full post. Ex:

Short post
(short post content)
Short post
(short post content)
Long post
(first few hundred words)
(read more)
Short post
(short post content)
Long post
(first few hundred words)
(read more)
Short post
(short post content)

I’m having trouble with figuring out how to do this within my blog index loop, as it doesn’t seem like I can use an operator when using the content helper. What I want to do is write something like the following:

{{#if content words > "500"}}
  <article>{{content}}</article>
  {{else}}
  <article>
    {{content words="300"}}
    <a class="read-more__link" href="{{url}}">
  </article>
{{/if}}

Does anyone have any guidance on this?

Handlebars doesn’t support any logical operators, and there’s not a Ghost theme helper that allows testing content length.

The recommended way to do something like this would be to use internal tags to mark content that you want to display differently. Then you can use the {{#has}} helper to distinguish between the different layouts.

2 Likes

Thank you Hannah! Hopefully something like this can exist in the future.