Just a general question today:
- Why do I need to add an API key to my template when I want to implement search for posts?
Just a general question today:
There are plenty of service which index your site and provide search functionality. They are better than a traditional simple query based search.
Your theme may implement search function using third party services that is why you need an api I guess.
No, I mean, a Ghost API key. The template is using the Ghost API for search.
@mattes3 Ghost’s Content API gives access to your site’s content in a more structured manner which is useful for building a search index.
Most template-driven search functionality (Ghost does not have built-in server-side search) will use client-side Javascript to fetch your site’s content using the Content API and build a local index that it can search across.
Yes, sure, but why does this need a key? The editor or the foreach-loop, they don’t need such a key, do they?
The foreach loop is run on the server so API access is implicit. The search is run on the client (web browser) so it needs to be given explicit access to the API.
The {{foreach}}
helper doesn’t actually access the API or do any data lookup, it iterates over the data that the theme template is “handed” by default. The {{get}}
helper is an alias to accessing the API, but server-side with implicit access as mentioned by Kevin.
The editor requires you to be logged in as a user and uses your cookie session to access the API rather than a key.
Ah, I see! Thanks, Hannah and Kevin!