I’m working on a theme and want to add advanced tag relevancy functionality with custom ordering using internal tags. I am sadly up against a wall now - either from lack of experience of via the Ghost arbitrary restrictuions.
Initially I wanted to create the following {{#get}}
expression:
{{#get "posts" filter="tags:{{tags[1].slug}}" include="tags" order="{{tags[2].slug}} asc" as |related-posts|}}
{{#foreach related-posts}}
{{> post-line}}
{{/foreach}}
{{/get}}
This would return all posts, including the current one, using the first tag (which by convention would’ve been internal theme tag) whilst then ordering by the second tag (which when ordered alphanumerically would allow the users to order their posts as they want with certain degree of structure, regardless of the last date of update or creation). This has naturally failed, since ghost doesn’t allow any expressions in order
. Fair play, I reversed the approach:
{{#get "tags" filter="visibility:internal+slug:~^'hash-chapter-order-'" order="slug asc" include="posts" as |related-tags|}}
{{#foreach related-tags visibility="all" as |tag|}}
{{#get "posts" filter="tags:{{../../tags.[1].slug}}" limit="all" as |related-posts|}}
{{#foreach related-posts}}
{{> post-line}}
{{/foreach}}
{{/get}}
{{/foreach}}
{{/get}}
Here, hash-chapter-order-'
is the prefix of an internal tag that’s used to define order for posts with the identical tags.[1] (second tag, which is also internal), whilst ../../tags.[1].slug
is supposed to represent the actual current post
’ tag object. No amount of ../
escaping matters since Ghost doesn’t seem to be too happy with ../
being there in the first place.
Now, this would work, in theory, and does work if I operate within JS against Content API. However, for some unknown reason, Ghost returns an error:
IncorrectUsageError: We detected a misuse. Please read the stack trace.
"registerAsyncThemeHelper: get"
And the stack trace reads:
Error: Parse error on line 1:
at Object.returnAsync (/ghost-cli/versions/5.79.0/core/frontend/services/helpers/handlebars.js:19:75)
../../tags[1].slug
^
Expecting 'DOLLAR', 'STAR', 'IDENTIFIER', 'SCRIPT_EXPRESSION', 'INTEGER', 'END', got 'DOT_DOT'
My question is - is there something wrong with the request and there IS a way to nest this, or did Ghost just decide that this shouldn’t be allowed because… reasons? I assume there’s a github conversation that can be read about this?
I want to ship it as a theme, therefore simply adding a helper is not viable since, if I understand correctly, these aren’t allowed to be used or “brought in” with a theme.
I would appreciate some enlightenment in this regard, because otherwise, as it stands, my only option would be to use “updated_at” for ordering an it will be incredibly disruptive since any update to a post would throw things entirely out of order in the ordered chapters navigation element I’m working on.
P.S. And yes, I tried {{#with}}
and it fails with the same exact error.