Leverage fragments in decision policies fragments
If your decision policy contains decision items including fragments, you can leverage these fragments in the decision policy code. Learn more on fragments
For example, let’s say you want to display different contents for several mobile device models. Make sure you added fragments corresponding to those devices to the decision item that you are using in the decision policy. Learn how.
Once done, you can use either one of the following methods:
Simply copy-paste the code block below into the decision policy code. Replace variable with the fragment ID and placement with the fragment reference key:
| code language-none |
|---|
|
-
Navigate to the Helper functions and add the Let function
{% let variable = expression %} {{variable}}to the code pane, where you can declare the variable for your fragment.
-
Use the Map > Get function
{%= get(map, string) %}to build your expression. The map is the fragment referenced in the decision item and the string can be the device model you entered in the decision item as the Fragment reference key.
-
You can also use a contextual attribute which would contain this device model ID.
-
Add the variable that you chose for your fragment as the fragment ID.
The fragment ID and reference key will be selected from the decision item’s Fragments section.
Guardrails when using fragments fragments-guardrails
Decision item and context attributes
Decision item attributes and contextal attribute are not supported by default in Journey Optimizer fragments. However, you can use global variables instead, such as described below.
Let’s say you want to use the sport variable in your fragment.
-
Reference this variable in the fragment, for example:
code language-none Elevate your practice with new {{sport}} gear! -
Define the variable with the Let function within the decision policy block. In the example below, sport is defined with the decision item attribute:
code language-none {#each decisionPolicy.13e1d23d-b8a7-4f71-a32e-d833c51361e0.items as |item|}} {% let sport = item._cjmstage.value %} {{fragment id = get(item._experience.decisioning.offeritem.contentReferencesMap, "placement1").id }} {{/each}}
Decision item fragment content validation
-
Due to the dynamic nature of these fragments, when used in a campaign, the message validation during the campaign content creation is skipped for fragments that are referenced in decision items.
-
The validation of the fragment content happens only during the fragment creation and publication.
-
For JSON-type expression fragments, the content is syntactically validated upon saving the fragment. Validation errors are displayed as alerts.
At runtime, the campaign content (including fragment content from decision items) is validated. In case of a validation failure, the campaign will not get rendered.