

<div class="admonition admonition-tip"><div class="admonition-icon"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2.5"><path stroke-linecap="round" stroke-linejoin="round" d="M9.663 17h4.673M12 3v1m6.364 1.636l-.707.707M21 12h-1M4 12H3m3.343-5.657l-.707-.707m2.828 9.9a5 5 0 117.072 0l-.548.547A3.374 3.374 0 0014 18.469V19a2 2 0 11-4 0v-.531c0-.895-.356-1.754-.988-2.386l-.548-.547z" /></svg></div><div class="admonition-body"><div class="admonition-content">

If you use Visual Studio Code as your editor, you can use code snippets to speed up working with inserts.  
You can find the snippets in our Github repository: [https://github.com/Synerise/jinja-code-snippet](https://github.com/Synerise/jinja-code-snippet)

</div></div></div>


## Common tags available in Screen Views and Documents

You can use all tags from [Insert usage](/developers/inserts/insert-usage).

## Recommendations

This inserts a recommendation result as a JSON object:


<pre><code class="language-jinja">{% recommendations_json3 campaignId=COhsCCOdu8Cg %} {% endrecommendations_json3 %}</code></pre>


If your campaign type is [External](/docs/ai-hub/recommendations-v2/abx-test-with-external-model), you need to provide the IDs of the items from the external model.  
- The IDs must be an array of strings.
- They must be declared with `{% set %}` and used as a variable.

Example:

<pre><code class="language-jinja">{% set externalItems = ['sku1','sku2'] %}
{% recommendations_json3 campaignId=COhsCCOdu8Cg externalItemsIds=externalItems %}
{% endrecommendations_json3 %}</code></pre>



#### Example

A document has the following content.

<pre><code class="language-json">"{% recommendations_json3 campaignId=FcP8UtRgrype %} {% endrecommendations_json3 %}"</code></pre>


The recommendation type of the requested campaign is "Top items". It's configured to return one item in a slot.

The output of the generated document is the following:

<pre><code class="language-json">{
  "campaignId": "FcP8UtRgrype",
  "campaignHash": "0cfa5c65-a62a-47d6-93f5-fa98eb346d6b",
  "recommended": {
    "data": [
      {
        "category": "Synerise Hub &gt; Use cases",
        "itemId": "21baa503-9c26-42a4-aebe-1e04adb0bf2e",
        "link": "https://synerise.com/use-cases/?snrai_campaign=FcP8UtRgrype&amp;snrai_id=0cfa5c65-a62a-47d6-93f5-fa98eb346d6b",
        "title": "Use cases"
      }
    ],
    "extras": {
      "contextItems": null,
      "correlationId": "0cfa5c65-a62a-47d6-93f5-fa98eb346d6b",
      "slots": [
        {
          "id": 0,
          "itemIds": [
            "21baa503-9c26-42a4-aebe-1e04adb0bf2e"
          ],
          "name": "Unnamed slot"
        }
      ]
    }
  }
}</code></pre>


## Documents

You can refer to a document in the following way:

<pre><code class="language-jinja">{% document SLUG %}</code></pre>


In this case, you can't pass variables to the document you refer to.

## Screen view collection

The `{% screenviewcollection %}` insert is added to a Screen View automatically when you create it in the Synerise Portal.

It inserts all the documents you added in the **Documents to display** section when configuring the Screen View.

## Handling variables when displaying screen views/documents
Screen views and documents may include variables. These variables may be profile attributes (including analytics such as expressions) or variables that are not part of a profile.

If the non-profile variables aren't declared in the screen view or document, they can be injected when making the request.


<div class="admonition admonition-tip"><div class="admonition-icon"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2.5"><path stroke-linecap="round" stroke-linejoin="round" d="M9.663 17h4.673M12 3v1m6.364 1.636l-.707.707M21 12h-1M4 12H3m3.343-5.657l-.707-.707m2.828 9.9a5 5 0 117.072 0l-.548.547A3.374 3.374 0 0014 18.469V19a2 2 0 11-4 0v-.531c0-.895-.356-1.754-.988-2.386l-.548-.547z" /></svg></div><div class="admonition-body"><div class="admonition-content">

In the document creator, you can [generate a preview with your own variable values](/docs/assets/documents/creating-documents#preview-body).

</div></div></div>



### In Mobile SDKs
When a screen view/documents is displayed by using one of the Mobile SDK methods:

- Values of inserts such as `{% customer ATTRIBUTE_NAME %}` or `{% expression %}` are fetched automatically from the profile authorized in the mobile app.
- Variables that use non-profile data, such as `{{ foo }}`, need to be added to `apiQuery.params` when using the "Generate document with query parameters" and "Generate screen view with query parameters" methods: 
    - [Android method reference](/developers/mobile-sdk/method-reference/android/content)
    - [iOS method reference](/developers/mobile-sdk/method-reference/ios/content)
    - React Native and Flutter will support this option in the future.

### In API

The API offers a number of endpoints to generate screen views and documents for display. They may require injecting profile attributes manually.

- Data for variables in the `{{ foo }}` format must always be added to the request, unless those variables are declared in the document.
- Data for inserts which insert profile attributes, such as `{% customer ATTRIBUTE_NAME %}` or `{% expression %}`:
    - Does NOT need to be added to requests with Profile authorization (example 1 below). The data is automatically fetched from the authorized profile.
    - Does NOT need to be added to requests which indicate a profile in their parameters (example 2 below). The data is automatically fetched from the indicated profile.
    - Needs to be added to requests Workspace/Synerise User authorization when they don't indicate a profile (example 3 below).


   <div class="admonition admonition-important"><div class="admonition-icon"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2.5"><path stroke-linecap="round" stroke-linejoin="round" d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" /></svg></div><div class="admonition-body"><div class="admonition-content">

   Some endpoints accept all types of authorization. In that case, you  need to inject data for profile inserts only when authorizing as a Workspace/Synerise User.<br>
   [/schema-service/v2/documents/{slug}/generate](https://developers.synerise.com/AssetManagement/AssetManagement.html#tag/Documents/operation/generateDocumentBySlug) is an example of such an endpoint.

   </div></div></div>


#### Examples

For the purpose of the examples below, assume the following document:
```
{
  "exampleCustomParameter": "{{ foo }}",
  "exampleExpression": "{% expression %}61722849-e004-48ef-a574-ee3702c88450{% endexpression %}",
  "exampleProfileAttribute": "{% customer email %}"
}
```

where:
- `{{ foo }}` is a variable that's not saved in the profile and not declared in the document.
- `{% expression %}61722849-e004-48ef-a574-ee3702c88450{% endexpression %}` returns the result of an expression. For the profile in this example, it's `segment2`.
- `{% customer email %}` inserts the `email` parameter from a profile.  

In the document creator, you can [generate a preview](/docs/assets/documents/creating-documents#preview-body) by providing a value for the `foo` value.


<div class="content-tabs" data-tab-group="tabgrp-9">
<div class="tab-buttons"><button class="tab-button" data-tab-id="tabgrp-9-0" data-tab-group="tabgrp-9" data-tab-active="true">Example 1</button><button class="tab-button" data-tab-id="tabgrp-9-1" data-tab-group="tabgrp-9">Example 2</button><button class="tab-button" data-tab-id="tabgrp-9-2" data-tab-group="tabgrp-9">Example 3</button></div>

<div class="tab-panel" data-tab-id="tabgrp-9-0" data-tab-group="tabgrp-9" data-tab-active="true">

This is an example of "Generate document" request authorized with a Profile JWT. Profile attributes and the expression value are fetched automatically.  

If you provide values for `exampleProfileAttribute` or `exampleExpression`, they are ignored.  
**Request**:

<pre><code class="language-plaintext">curl --location 'https://api.synerise.com/schema-service/v2/documents/example-1/generate' \
--header 'Authorization: Bearer PROFILE_JWT' \
--header 'Content-Type: application/json' \
--data '{
    "foo": 12
}'</code></pre>


**Output**:

<pre><code class="language-json">{
    "uuid": "98ed0cef-ed81-4fc7-83e8-638f2009174d",
    "slug": "example-1",
    "schema": "examples",
    "content": {
        "exampleCustomParameter": "12.0",
        "exampleExpression": "segment2",
        "exampleProfileAttribute": "example@synerise.com"
    }
}</code></pre>


API reference: [/schema-service/v2/documents/{slug}/generate](https://developers.synerise.com/AssetManagement/AssetManagement.html#tag/Documents/operation/generateDocumentBySlug)

Other endpoints with the same behavior:
- [/schema-service/v2/documents/{documentId}/generate](https://developers.synerise.com/AssetManagement/AssetManagement.html#tag/Documents/operation/generateDocumentByIdPost)
- [/schema-service/v3/screen-views/{feedSlug}/generate](https://developers.synerise.com/AssetManagement/AssetManagement.html#tag/Screen-views/operation/generateScreenViewByFeedPostV2)

</div>

<div class="tab-panel" data-tab-id="tabgrp-9-1" data-tab-group="tabgrp-9">

This example shows generating a document with a profile context. This request is authorized with a Workspace JWT, but it specifies the profile, so the profile attribute and expression value are fetched automatically.  

If you provide `exampleExpression` or `exampleProfileAttribute` in the request, they are ignored.  
**Request**:

<pre><code class="language-plaintext">curl --location 'https://api.synerise.com/schema-service/v2/documents/example-1/generate/by/id' \
--header 'Authorization: Bearer WORKSPACE_TOKEN' \
--header 'Content-Type: application/json' \
--data-raw '{
    "identifierValue": "8701078606",
    "params": {
        "foo": 12
    }
}'</code></pre>


**Output**:

<pre><code class="language-json">{
    "uuid": "98ed0cef-ed81-4fc7-83e8-638f2009174d",
    "slug": "example-1",
    "schema": "examples",
    "content": {
        "exampleCustomParameter": "12.0",
        "exampleExpression": "segment2",
        "exampleProfileAttribute": "example@synerise.com"
    }
}</code></pre>


API reference: [/schema-service/v2/documents/{documentIdentifier}/generate/by/{identifierType}](https://developers.synerise.com/AssetManagement/AssetManagement.html#tag/Documents/operation/generateDocumentWithProfileContextPost)

Other endpoints with the same behavior:
- [/schema-service/v2/screen-views/{feedSlug}/generate/by/{identifierType}](https://developers.synerise.com/AssetManagement/AssetManagement.html#tag/Screen-views/operation/generateScreenViewByIdentifierPostV2)

</div>

<div class="tab-panel" data-tab-id="tabgrp-9-2" data-tab-group="tabgrp-9">

This example uses the same endpoint as Example 1. This time, the request is authorized with a Workspace JWT, so the profile attribute must be injected to process the document.

The value of the expression will always be `"N/A"`. If you provide `exampleExpression` in the request parameters, it will be ignored.  
**Request**:

<pre><code class="language-plaintext">curl --location 'https://api.synerise.com/schema-service/v2/documents/example-1/generate' \
--header 'Authorization: Bearer WORKSPACE_TOKEN' \
--header 'Content-Type: application/json' \
--data-raw '{
    "foo": 12,
    "customer.email": "example@synerise.com"
}'</code></pre>


**Output**:

<pre><code class="language-json">{
    "uuid": "98ed0cef-ed81-4fc7-83e8-638f2009174d",
    "slug": "example-1",
    "schema": "examples",
    "content": {
        "exampleCustomParameter": "12.0",
        "exampleExpression": "N/A",
        "exampleProfileAttribute": "example@synerise.com"
    }
}</code></pre>


API reference: [/schema-service/v2/documents/{slug}/generate](https://developers.synerise.com/AssetManagement/AssetManagement.html#tag/Documents/operation/generateDocumentBySlug)

Other endpoints with the same behavior:
- [/schema-service/v2/documents/{documentId}/generate](https://developers.synerise.com/AssetManagement/AssetManagement.html#tag/Documents/operation/generateDocumentByIdPost)
- [/schema-service/v3/screen-views/{feedSlug}/generate](https://developers.synerise.com/AssetManagement/AssetManagement.html#tag/Screen-views/operation/generateScreenViewByFeedPostV2)

</div>
</div>
