Query Components
It may happen that a frontend component needs to display a set of contents or digital assets present in the CMS. For example, let's imagine a component that displays "featured products" or "what's new videos".
If in your site/app there are many of these components that have the same appearance, but carry out queries according to different criteria, it is advisable to configure a single component on the CMS side which contains the configurable information to carry out the query, so that this is not completely hard coded into the application.
For example, a common case might be related to the use of taxonomies as filter criteria. Let's imagine a component that displays a horizontal line made up of N images (or products) that have the "Recommended" category and that this component should appear on the home page.
Below is a series of possible approaches:
- hard code: the component could directly perform the query by filtering by
category = Recommended
. In this case the "Recommended" value would be encoded in the frontend application and if it is necessary to change it (e.g. to "What's new") it is necessary to redeploy the app. - (controlled by the CMS) a corresponding Component is created on the CMS with a "Category" field. The frontend component retrieves this information from the CMS to determine the type of category to search for. This allows the publisher to change his mind over time and perform different queries without requiring a new deployment of the application.
- (controlled by the CMS, advanced) you create a JSON field on the corresponding CMS Component and in the JSON field you insert the options to pass to
DiscoveryCms.getContents()
. In this case the frontend first retrieves the query and then executes it. It requires the administrator on the backend to be expert to know the API query format.