Setting global variables


#1

I hope I’m missing something which would make things easier when revealed, but with what I got to learn about ghost handlebars this far, there’s no way to set custom variables and reuse them outside their scope.

When building queries, one may want to either include more than one specific set or explicitly exclude posts that were already displayed.

This can be done inside a wrapper get but in a rather primitive way and it would take too much nesting, which it’s warned against anyway.

For example, I may want to do several consecutive loops and exclude whatever was already displayed before. A global array of exclusions would come very handy for that instead of having to nest gets.

Or do more than one query at once, build an initial list of posts and then sort them out in a second step.

It would be even greater if they could be pushed to a key-value array in order to be able to assign sorting weights to them.

I’m aware that this sounds like a lot of effort for something that few people are interested in and I’m not too aware of how complicated it may be - but I’m writing this hoping that there’s some not-too-difficult way to achieve what I’m looking for that I might have missed.


#2

Seeing that this was moved from “Ideas” to “Help”, I’m getting optimistic that it is indeed possible :smiley:


#3

It’s not clear what you’re trying to accomplish. The original post is neither an idea or a question, so I’m not sure it’s going to get much of a response here.

It sounds like you’re trying to do complex operations on data, which is not at all what handlebars is designed for. You’re probably best off simply interacting with the Content API directly and writing clientside code to do what you want.

If clientside fetching isn’t sufficient, then you may want to look at using a different front end instead of Ghost Handlebars themes, eg. Gatsby:


#4

I’m trying to - 1st - reliably avoid duplication of post snippets between different loops and - 2nd - allow a snippet to slowly flow from a more important to a lesser important loop, instead of going straight into oblivion.

If this two things were possible, I suppose it might allow for even more customisation.

I’m aware that it’s complicated with Handlebars, but I’ve noticed some hints that suggest it may not be totally out of reach.


closed #5

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.