$wsExternalData module, you load file-based external data (JSON) from the shop’s own S3 into your templates and process it there. Typical use cases are additional information that does not come from the standard shop data, for example PDF lists for a product or content from WEBSALE components such as a Strapi instance.
This page covers read access to stored files. Populating the buckets (upload, Strapi export) is done via the data interface, not via this module.
Basic concept
$wsExternalData has no variables of its own. Instead, you load data via a method into a template variable of your own and then continue working with it. The flow is always the same:
- Load -
load()reads a file and returns its contents; you assign the result to a variable (e.g.$data). - Check - you check with
{{ if $data }}whether the loading succeeded. - Output - only then do you iterate over or display the contents.
Always check for success
External data may be missing or unreachable (wrong path, empty bucket, access problem). Therefore, always wrap the output with{{ if $data }} – otherwise empty placeholders or “dead” HTML structures arise. In the error case, getLastError() returns a diagnostic message (for development only, not for the frontend).
How the three methods work together
load()loads the contents of a file (map or list, depending on the JSON).read()lists the files of a directory without loading their contents – useful to dynamically determine which files are present and then load them withload().getLastError()returns the last error message.
Data sources (source)
Both loading methods know two sources: user (bucket external-data, default) for your own project-related files, and system (bucket system) for files provided by WEBSALE components (e.g. Strapi exports).
Note on timing
load() and read() access S3 during page rendering. Each call is a network request. Therefore, load only what the page needs, instead of unnecessarily loading many files per page view.
Module overview
Example / excerpt of$wsExternalData
"ƒ()" denotes a function.
Methods overview
| Method | Return type | Description |
|---|---|---|
load() | map | list | Loads the contents of a JSON file. |
read() | list | Lists the files of a directory (without contents). |
getLastError() | string | Last error message from load() / read(). |
Templates
External data can be loaded into any template, depending on the use case for example on product detail pages (additional data), category pages (additional lists), or content pages.Variables
$wsExternalData does not provide any variables of its own. The loaded data is stored in the template variable to which you assign the result of load() (see Basic concept).
Methods
$wsExternalData.load()
Loads the contents of a file from the external data interface and returns it, depending on the JSON structure, as a map (for an object) or a list (for an array), so that it can be output in the template (e.g. PDFs, additional attributes, CMS content). Signature$wsExternalData.load(file, options)
Return valuemap | list – depending on the JSON structure, empty/null in the error case.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
file | string | yes | Path to the file within the source (e.g. products/product_123.json). |
options | map | yes | Format and source options (see table). |
options)
| Key | Type | Required | Default | Description |
|---|---|---|---|---|
type | string | yes | – | File format. Currently allowed: json. |
source | string | no | user | Data source: user (bucket external-data) or system (bucket system). |
maxDepth | int | no | 7 | Limits the read depth of nested JSON structures; deeper levels are truncated. |
$wsExternalData.read()
Lists all files of a directory of the external data interface (optionally including subfolders) and returns their paths as a list. The file content is not loaded; useload() for that afterwards. Helpful when you need to determine dynamically which files are present in a directory.
Signature$wsExternalData.read(path, options)
Return valuelist – paths of the files found.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
path | string | yes | Directory path within the source (e.g. json/Deutsch/). |
options | map | no | Source and filter options (see table). |
options)
| Key | Type | Required | Default | Description |
|---|---|---|---|---|
source | string | no | user | Data source: user or system. |
recursive | bool | no | false | true: also search subfolders. |
glob | bool | no | – | Switches the pattern interpretation on/off. Expects a boolean, not a pattern string (see note). |
$wsExternalData.getLastError()
Returns the last error message as a string if an error occurred duringload() or read() (e.g. file not present, access not possible). The message is intended for troubleshooting and should not be output to customers in the frontend.
Signature$wsExternalData.getLastError()
Return valuestring – error description, or empty/null if no error is present.
Output the error message only to the console (development), never visibly in the frontend. The
autoescape "js" block ensures that special characters in the message do not break the surrounding script.Actions
No actions are available for$wsExternalData.
Examples
Load and display product additional data (PDF list)
A common case: PDF links are maintained for a product via a JSON file. For product137497, the file under products/137497.json contains:
A list of linked PDFs. But only if the file was loaded and contains a
pdf array.
Load CMS/Strapi content from the system source
From the system bucket, you typically load Strapi exports. In Content, Strapi mixes different block types. Each block carries a __component field, which you can use to filter selectively.
Only blocks of type
elemente.categories are rendered via the matching component. Other block types are skipped.
List the files of a directory
Withread(), you determine which files are present without loading their contents. You then load the contents specifically with load().
All matching files are found and loaded one by one.
Loading with error handling
Output only on success; otherwise write the error message to the console.On success, the data appears; otherwise the cause of the error ends up in the browser console.
If you build a path from several components, you can join an array into a string with
| join before passing it to load() / read(). For a fixed path, the string by itself is sufficient (as in the examples above).Related links
- External data interface (file-/bucket-based) – defines which buckets/sources exist and how files are stored.
- join function – joins an array into a string (for composed paths).
