-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Query (get) helper #4439
Comments
+1 I'm for the second option, inconsistencies and all. I see it as a function with arity of two, the first being resource, the second being an options hash :) Assuming this has a built-in loop, is there anything that needs to be considered with nested fetch calls? I'm not feeling clever enough to come up with an example of when or why you'd do that, but... implementation-wise, nothing scary happens eh? |
This would very,very good. It would allow Ghost to function as a sweet hybrid between blogging system and a typical CMS. This would allow post content to be plugged directly into table cells (eg bootstrap) by id or a set of ids, without having to implement a bunch of repetitive {{foreach}} loops looking for a post with {{has}}. You'd be able to move content out of templates for pages where a blog sequence is not needed and into the admin interface. I would suggest taking the tags concept above and extending it to specific named tags in the fetch syntax: {{fetch "posts" tag="mytag"}} -- this would immediately lead to an easily maintainable site structure and open up a variety of theming options for users. |
The more I think about it, the more I prefer the second option as well:
However, I'm leaning towards using
|
Personally, I like #get over #fetch and I like option 2 as well. Seems the most straight forward and readable. |
Here's a little bit of how I imagine it working: In post.hbs, display the 5 most recent posts in a sidebar:
In index.hbs, display a list of all tags in a sidebar:
|
Instead of the |
@halfdan good catch!! Updated my comment to demonstrate this + else. |
An update on the status of this issue, which also applies to #4799. I began work on implementing this, and ran into a small oversight - express-hbs's fancy async helpers don't work for block helpers. Essentially, the options don't get passed around the same way so access to Note: Handlebars itself has no intention of supporting async helpers. |
My current workaround with redefined |
@ofstudio thanks for dropping by and sharing that gist with us - it gave me some inspiration and now the issue is fixed in express-hbs 0.8.3 ;) |
fixes TryGhost#4364, refs TryGhost#4439, refs TryGhost#4799 - Update express-hbs to 0.8.5 - Use preventIndent option onCompile - Update registerAsyncHelper to support passing through options when needed
@ErisDS +1 👍 For this feature! Certainly theme developers are running into a wall without this. 2 Questions though:
|
This helper is relatively simple, the problem at the moment is the API itself is still very, very limited so even if I put it in master, the helper wouldn't do enough things. As it has (so far) not been accessible except for in the admin interface, it's got a few gnarly bits and limitations which are far too tailored to that scenario and not any where near general enough. There's a balance to be had here, because I know as soon as the The most important one of those is the horrid Some other notes on API limitations:
So I imagine the second we put a helper out there, theme devs are going to want more options 😁 |
Any news on this issue. I'm currently working on a theme that will take advantage of the GET feature, so I was wondering if I should work around it or wait. |
If you look at the links above your comment, you'll see there are currently 2 open PRs against this issue - they are the news 😉. Rather than working around or waiting, I recommend testing them out and letting us know how you get on - feedback will help us ship. |
😕 |
Hi @ErisDS I want to help with the testing of this feature. Do I have to wait for the WIP to be merged into master or can I check it out already? Thanks |
@gazpachu You can checkout PRs for local testing. There's a good guide to make the process super simple on the dev blog - http://dev.ghost.org/easy-git-pr-test/ |
Thanks @kevinansfield. I was able to checkout "upstream/pr/5619" and test it in a clean Ghost install. I've placed the get helper snippet (like in ErisDS example) in the post template and in a new static page. It returns correctly all the posts in the DB (except the static pages),
How can I access #5496 in my current PR checkout to make the tags work? The error handling doesn't render any error message either. I've also noticed in the admin area that the tags field is not present, so I can't add tags to new posts from the admin. Is that expected? Are you adding tags manually using an external DB GUI? What else can I test? |
closes TryGhost#4439 - adds get helper + tests
Hi @gazpachu, #5496 is already merged and so is included whenever you check out one of the get helper PRs. If you want to play with the more advanced filter features then I recommend checking out #5608, rather than #5619. The tag field for adding tags to posts is now under the post settings menu, but you'll need the latest copy of the PRs as it was missing entirely for a while. I have updated both of the PRs - #5619 is just the get helper & #5608 is the get helper & filter feature - they have both been rebased on master today so when you check one of them out you'll have all of the code as of today + these extra features, which should make it easier to test. |
Hello. How is this going? I'm currently developing a theme for Envato Ghost Theme Contest and would like to know the status. |
i need offset of post |
Hi, |
+1 waiting looking forward to this feature. @ErisDS I agree with your syntax. I'm looking for: |
closes TryGhost#4439 - adds basic get helper which works with the current API - allows theme developers to make requests against the API - supports block params and @error message - includes 100% test coverage using posts ---- The `{{#get}}` helper is an asynchronous block helper which allows for making requests for data from the API. This allows theme developers to customise the data which can be shown on a particular page of a blog. Requests can be made to the posts, tags or users API endpoints: ``` {{#get "posts" limit="3"}} {{#foreach posts}} <a href="{{url}}">{{title}}</a> {{/foreach}} {{/get}} ``` The `{{#get}}` helper must be used as a block helper, it supports `{{else}}` logic, for when no data matching the request is available or if an error has occurred: ``` {{#get "posts" tag="photo"}} ... {{else}} {{#if @error}} <p>Something went wrong: {{@error}}</p> {{else}} <p>No posts found</p> {{/if}} {{/get}} ``` The helper also supports block params, meaning the data it outputs can be given a different name: ``` {{#get "posts" featured="true" as |featured|}} {{#foreach featured}} ... {{/foreach}} {{/get}} ``` Please Note: At present asynchronous helpers cannot be nested.
👍 |
I'm just wondering when this feature will be available? |
It is coming in Beta in the next release. That's the only thing I can say for certain 😉 |
I'm So damn excited for this feature @ErisDS ! |
Hi! Someone seen theme that supports the new query |
@online the beta version of the get helper just came out so i doubt any themes already have it running. You can however check out how to do it yourself here (http://themes.ghost.org/v0.7.2/docs/get#section-make-a-tag-cloud) or here (https://www.ghostforbeginners.com/how-to-add-a-tag-menu-to-your-blog/) |
@dbalders thank you, this is just what I need! 😉 |
One of the main new features we need to add to Ghost is a 'query helper' for themes. This is a helper that gives theme developers access to the API to make custom queries for data they'd like to display.
This helper will only provide access to the
GET
API endpoints that don't require user authentication - that is getting published posts, and all tags, with all the sorting and filtering options which are available.I propose that this helper be a block helper called 'fetch':
After that, there are a number of ways we could specify the details of the API call we want to make:
{{#fetch "/posts/?limit=5"}}
{{#fetch "/posts/12/?include=tags"}}
{{#fetch "posts" limit="5"}}
{{#fetch "posts" id="12" include="tags"}}
{{#fetch resource="posts" limit="5"}}
{{#fetch resource="posts" id="12" include="tags"}}
We need to find a format that makes sense to theme developers. Using the API call URL as a string is very simple to implement, but all the
/
's and?
's and&
's look quite complex even though URLs are fairly well understood thing.The second option is kind of inconsistent with itself, but it looks nice. It's also similar to doing something like
{{date published_at format="dd mm YY"}}
where there can be a parameter and an attribute, and just like the date helper defaults to published_at, the fetch helper can default to posts.The third one makes everything consistent, but as soon as you start using named parameters you need to do something like
id="12"
orslug="welcome-to-ghost"
if you want to specify an id, or a slug etc to fetch a specific resource.Thoughts on a postcard please!
The text was updated successfully, but these errors were encountered: