PDP Metadata Javascript Mapper
You can use the Javascript Mapper display type on PDP metadata blocks to transform metadata into custom HTML.
What This Feature Can Do
#
- Accept many metadata shapes for the selected metadata key:
- JSON arrays
- JSON objects
- plain text
- other primitive values
- Run mapper code that receives one input variable:
metadata. - Support both mapper authoring styles:
- function body
- function expression
- Return an HTML string that will be rendered in the PDP metadata block.
- Test mapper output in manager using sample metadata (or manual input).
Mapper Input and Output Contract
#
Input
#
Your mapper receives:
Cloudshelf attempts to parse metadata as JSON first. If parsing fails, it passes the raw string value.
Output
#
Your mapper must return HTML as a string.
If your return value is not a string, it is coerced into a string.
Examples
#
Example 1: Function Body
#
Example 2: Function Expression
#
Example 3: Local Helper Functions
#
Limitations
#
- No module imports inside mapper code.
- No async mapper execution; mapper is synchronous.
- Return HTML only. React components are not supported.
- Heavy computation on large arrays may impact PDP render performance.
- Preview output depends on preview sample data and can differ from live metadata at runtime.
Troubleshooting
#
expected expression, got keyword 'if':- Use function body mode (starting with
if) or wrap code as a full function expression.
- Use function body mode (starting with
- Blank output:
- Ensure every code path returns a value.
- Unexpected output:
- Confirm actual metadata shape in the preview panel.
Previous
Custom Card Payment
Next
- Connectors
Shopify