Building a JSON feed
In this objective we will explore the use of alternate outputs from the Squiz CMS that are not HTML, for example JSON.
In this section we will:
- Locating the JSON Design.
- Selectively apply the the design to content
- Customise the output with Squiz CMS Tools
Locating the JSON Design
Squiz CMS Design Assets
Design parse files are used to create a skeleton structure around your content.
They can also be used to declare the parse files mime type as we will see.
For this task we have already created the JSON Design file for you.
This can be found by navigating to the JSON Design within the 'Designs' folder under the 'DXP Site Design'.
Any code displayed in parse file will appear in the page, this can be static or dynamic content from the underlying asset it is applied to.
- Right click on the JSON Design file
- Select 'Edit Parse File' from the options menu
The only code you should see in the design file is the Mime Type Header & the Body Content Area.
<MySource_print id_name="__global__" var="content_type" content_type="application/json" /> <MySource_AREA id_name="page_body" design_area="body" />
Where ever you now apply the design the server will respond with the application/json mime type.
Squiz CMS MIME Types
This works for any mime type, see the manuals for more information.
Apply the the design
Designs or customisations can be selectively applied to a whole website, a section of a website or to individual pages within a website.
Select and clone the "Building a JSON feed" asset listing in your site, calling it "Building a JSON feed - JSON".
In the asset map, right click on your new asset and select Settings > Designs.
- Acquire the locks
- Select the "design" asset picker and
- Select the new JSON design Parse file from the asset map
- Save
- Preview the asset
The content will not look great as we are including the HTML content with a JSON header.
To fix this we will update the asset listing to output in a JSON format.