Getting Started
This feature lets you dynamically insert product information into your dynamic templates, using the “Generate Dynamic Content” rule in the PIM. Imagine you want to create a product description that includes the product's name and color. To do this, you'll use the attribute codes assigned to these properties in your PIM.
Here's a basic example:
Let's say you have a product and want to include its name, stored in an attribute called product_name, and its color, stored in an attribute called product_color, in your description. You would write the following template:
This product is called {{ product.product_name }} and its color is {{ product.product_color }}.
When this template is processed, it will be replaced with the actual values from the product. For instance, if the product's name is "Elegant Lamp" and its color is "Golden", the output would be:
This product is called Elegant Lamp and its color is Golden.
Key Takeaway:
- Replace product_name and product_color in the example with the actual attribute codes from your PIM.
- The general format is {{ product.attributecode }} where attributecode is the code of the attribute you want to retrieve.
- The table below provides more detailed examples for various attribute types and advanced options.
Remember that the feature uses Twig, a powerful templating language. While basic usage is straightforward, you can refer to the provided Twig documentation for more complex operations.
Create your rule
To create a dynamic content rule:
- Go to “Settings”
- Click on “Rules”
- Click on create and fill in a code and a label for your rule
- Click “Save”
- Define your product selection
- Add the action called “Generate Dynamic Content”
- Write your content using values from your products
- Select the target attribute
Integrate product values in your dynamic content
Here is a table with most common ways to retrieve values from a product.
If you need more advanced information go the next section of this page. Keep in mind this a just a sum of common expressions but you may need to use most advanced Twig configurations depending on your needs.
Here is a list of attributes types & properties available : Text, Number, Measurement, Price, Simple Select, Reference entity single link, Family, Category
Attribute type | Capabilities (not exhaustive) | Expression to use in your dynamic template | Example of output |
---|---|---|---|
Text Attribute | Display the full text | {{ product.Attributecode }} | My text |
Display the text of a specific locale (localizable attribute) | {{ product.Attributecode(null, 'fr_FR') }} | Mon Texte | |
Display the text of a specific channel and locale (localizable & scopable attribute) | {{ product.Attributecode('ecommerce', 'fr_FR') }} | Mon autre texte | |
Number Attribute | Display the number | {{ product.Attributecode }} | 1 |
Display the rounded number using round filter | {{ product.AttributeCode | round }} | 1234.1400 | |
Display the rounded number with 2 decimals using round filter | {{ product.AttributeCode | round(2) }} | 1234.14 | |
Display the number with 2 decimals, a space for thousands and a dot for decimals using number_format filter | {{ product.Attributecode | number_format(2, '.', ' ') }} | 1 234.14 | |
Measurement Attribute | Display the number & the unit | {{ product.Attributecode }} | 6000.0000 CENTIMETER |
Display the number only | {{ product.AttributeCode | amount }} | 6000.0000 | |
Display the unit only | {{ product.AttributeCode | unit }} | CENTIMETER | |
Display the rounded number only using round filter | {{ product.AttributeCode | amount | round }} | 6000 | |
Display the number only with 2 decimals, a space for thousands and a dot for decimals using number_format filter | {{ product.Attributecode | amount | number_format(2, '.', ' ') }} | 6 000.00 | |
Price Attribute | Display the number & the currency | {{ product.Attributecode }} | 2500.12 EUR, 2400.00 USD |
Display the number only of a specific currency | {{ product.Attributecode | price('EUR') }} | 2500.12 | |
Display the number only of a specific currency using round filter | {{ product.Attributecode | price('EUR') | round }} | 2500 | |
Display the number only with 2 decimals, a space for thousands and a dot for decimals using number_format filter | {{ product.Attributecode | price('EUR') | number_format(2, '.', ' ') }} | 2 500.12 | |
Apply a country specific currency format using format_currency filter | {{ product.Attributecode | price('EUR') | format_currency('EUR', {}, 'fr') }} | 2 500,12 € | |
Simple Select Attribute | Display the code of the attribute option | {{ product.Attributecode | optionCode }} | optioncode |
Display the label of the option in the locale of destination | {{ product.Attributecode | optionLabel(target.locale) }} | Option Label | |
Display the label of the option in a specific locale | {{ product.Attributecode | optionLabel('fr_FR') }} | Label de l’option | |
Apply a default value when the label is empty using the default filter | {{ product.Attributecode | optionLabel('en_US') | default('default label') }} | default label | |
Multi Select Attribute | List all option codes, separated by a comma | {{ product.Attributecode | optionCode }} | optioncode1,optioncode2 |
List all option codes, separated by a comma | {{ product.Attributecode | optionCode }} | optioncode1,optioncode2 | |
List all option labels in a specific locale, separated by a comma | {{ product.Attributecode(null, 'en_US') | optionLabel('en_US') }} | option label 1,option label 2 | |
Reference entity single link Attribute | Display the code of the reference entity record | {{ product.Attributecode }} | record_code |
Display the label of the reference entity record in the locale of destination | {{ product.Attributecode | recordLabel(target.locale) }} | Record Label | |
Display the label of the reference entity record in a specific locale | {{ product.Attributecode | recordLabel('en_US') }} | Record Label | |
Apply a default value when the label is empty using the default filter | {{ product.Attributecode | recordLabel('en_US') | default('default label') }} | default label | |
Reference entity multiple link Attribute | Display the codes of the reference entity records, separated by a comma | {{ product.Attributecode }} | record_code1, record_code2, record_code3 |
Display the labels of the reference entity records in the locale of destination, separated by a comma | {{ product.Attributecode | recordLabel(target.locale) }} | Record Label 1, Record Label 2, Record Label 3 | |
Display the labels of the reference entity records in a specific locale, separated by a comma | {{ product.Attributecode | recordLabel('en_US') }} | Record Label 1, Record Label 2, Record Label 3 | |
Categories | List all categories of a product with their codes, separated by a comma | {{ product.categories | join(', ') }} | camcorders, cameras_sales |
List all categories of a product with their label of a specific locale, separated by a comma | {{ product.categories | categoryLabel('en_US') | join(', ') }} | Camcorders, Cameras | |
List all categories of a product with their label of the locale of destination, separated by a comma | {{ product.categories | categoryLabel(target.locale) | join(', ') }} | Caméscopes numériques, Caméras | |
Family | Display the family code | {{ product.family }} | camcorders |
Display the family label in the locale of destination | {{ product.family | familyLabel(target.locale) }} | Caméscopes numériques | |
Display the family label in a specific locale | {{ product.family | familyLabel('en_US') }} | Camcorders | |
UUID | Display the product UUID | {{ product.UUID }} | 2a443ff2-f9f6-4cfc-bba8-eb15b10ef8cc |
Generate a UUID in a specific attribute | {{ uuid() }} | 1a6aad95-7f69-46f8-a7a7-68fe6f7013b7 |
Preview your dynamic content
Before applying your rule to all target products, use the preview feature to verify that your content generates as expected.
Steps:
- Enter your template: In the designated area, type or paste your dynamic content template.
- Select a preview product: Click the "Preview Product" button and choose a specific product or product model from the list.
- Review the results: The preview will display the generated content for up to 3 matching products and/or product models. For accurate results, especially with complex templates, it's recommended to initially shorten your product selection with a single, representative product.
- Refresh the preview: After making changes to your template, click the refresh icon (arrows) in the top right corner to update the preview.
Note: Some dynamic content might be generated (and previewed) as empty in the following contexts:
- The attribute is empty for the product.
- There is a syntax error in the dynamic value (incorrect attribute code, invalid characters, etc.).