Accessing the shop templates
Strapi defines structure and content (content types, components, fields). The shop templates define how this content is displayed in the shop. When something changes in Strapi (new component, new field, field renamed), the corresponding shop template must be adapted, since otherwise nothing, only part, or the wrong thing is displayed in the shop. To be able to adapt templates, you need access to the corresponding shop template repository in GitLab. You can find more information here. There are usually two use cases for adapting templates:- Modifying existing components (field added/renamed/removed)
- Adding new components (component did not exist in the template before)
An existing component has been changed
An existing Strapi component is considered changed when, for example, a field has been added, renamed, or removed. For the change to be visible in the shop, the rendering in the corresponding template must be extended or adapted.Determine the template
We recommend a pragmatic approach using the search in GitLab to determine the template in which the adjustment must be made. For example, search for:- Component name (for example
slider,imageLink,promoBanner) - Field name (for example
autoplayDelay,linkUrl,headline) - Component identifier from the JSON data, if available (often for example
__componentor a type/slug specification)
Determine the JSON file
So that you can later specifically load or download the component, you must identify the specific JSON file in which the component data is stored. Since the component is already in use in the shop, the corresponding JSON file is usually already loaded somewhere in the template. Recommended procedure:- Via the template (fastest way): Search in the relevant template for places where data is loaded – typically via
$wsExternalData.load(...)(a file) or$wsExternalData.read(...)(directory). Thepathused there indicates which JSON file(s) are used in the rendering. - Via S3/object storage: Download the file(s) from the relevant directory and search them for the component identifier (for example
content.imageLinkor__component). This way you can find out in which file the component is actually contained.
Publishing in test mode
If content from Strapi should initially only be visible in test mode, the JSON can be placed in a separate subfolder (for example/test). In the template, the path to the JSON file is then switched depending on the test mode.
Example:The JSON file is additionally placed in a
/test subfolder for test content. When test mode is active ($wsTestMode.active), the template automatically loads the test JSON from this subfolder. This way, adjustments in the template or new / adapted Strapi components can be tested without affecting the live output.
Check the JSON
Before you change the template code, you should check how the component is actually delivered as data. This helps in particular to avoid typos and incorrect assumptions about field names. Depending on the setup, there are two common ways:- Output/debug in the template, for example at the place where the data is processed via
$wsExternalData.load(...). - Download from the object/file storage (for example S3), provided that the generated files are stored there and you have access.
Example: component “Image with link” gets a new field
In Strapi, a component namedimageLink exists. This component initially has the fields image and linkUrl.
Data transfer JSON before the component change
imageLink component is extended with another input field, for example text. As a result, the data structure additionally contains the new value:
Data transfer JSON after the component change
A new component has been created
Choose a template or create a template
When a new component has been created in Strapi, there are two typical target scenarios:- The new component should be displayed on an existing page
Open the template of this page and select the place where content/components are rendered (for example the area where content blocks are output). - The new component should be displayed on a new page
Create a new view template and implement the loading and rendering of the data there.
Determine the JSON file
To output the contents of the component in the template, you must load the JSON file in which the component data is stored. For this, the file name must be known. Recommended ways to determine the file name:- Via
$wsExternalData.read(...):
If the theme reads in a directory viaread, a file list can be output via this. This way, the relevant file name can be found and then specifically loaded viaload. - Via S3/object storage:
If you have access to S3, the relevant directory can be opened and the file(s) identified by name/structure or by searching for the component identifier (for example__component).
Check the JSON data
Before the rendering is implemented, the JSON should be checked so that the following are clear:- what the component is called (for example
content.promoBanner) - which fields are delivered (for example
image,linkUrl,text) - what nested structures look like (for example image object, lists)
Example: integrate a new component
You have identified the JSON file that contains the data of your new component (for examplemy-new-component.json) and already looked at the structure:
Data transfer JSON before the component change
my-new-component.json, you must first load the file:
