How to get length of count.posts in {{if}}?

I’d like to get the length of the count.posts, so I can display examples like this:

1 post
2 posts

So I tried this:

<div class="post-count">{{ count.posts }} post{{#if count.posts.length > 1}}s{{/if}}</div>

But unfortunately it doesn’t recognize .length

Does anyone know how I could do this?

The error I’m getting:

Parse error on line 41: … count.posts.length > 1}}s{{/if}} -----------------------^ Expecting ‘CLOSE_RAW_BLOCK’, ‘CLOSE’, ‘CLOSE_UNESCAPED’, ‘OPEN_SEXPR’, ‘CLOSE_SEXPR’, ‘ID’, ‘OPEN_BLOCK_PARAMS’, ‘STRING’, ‘NUMBER’, ‘BOOLEAN’, ‘UNDEFINED’, ‘NULL’, ‘DATA’, ‘SEP’, got ‘INVALID’

The if block doesn’t support expressions, but it looks like you’re trying to configure pluralization. If so, the plural helper is for you :grin:

1 Like

Allright thanks that worked!

1 Like