> ## Documentation Index
> Fetch the complete documentation index at: https://product-discovery.developer.voyado.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Email campaign template model

> Advanced templating for Voyado Elevate Email recommendations campaign templates.

The campaign template model defines attribute names and functions that can be used inside a template. The main elements are [blocks](#campaign-blocks) and [product positions](#product-positions) in blocks.

The campaign template model and the [product template model](/elevate/docs/addons/email-recommendations/product-templates/template-model) are similar and share the same set of [lambda expressions](/elevate/docs/addons/email-recommendations/product-templates/template-model#lambda-expressions), and work the same way with [conditional content](/elevate/docs/addons/email-recommendations/product-templates/template-model#conditions) and [collections](/elevate/docs/addons/email-recommendations/product-templates/template-model#collection-extension). The campaign template works with campaign parameters in a similar way to how the product template model works with product parameters.

## Campaign name

The name of the campaign.

### Syntax

```handlebars icon="code" theme={null}
{{campaignName}}
```

## Campaign description

The optional campaign description.

### Syntax

```handlebars icon="code" theme={null}
{{campaignDescription}}
```

### Examples

```handlebars title="Print description if not empty" icon="code" theme={null}
{{#campaignDescription}} <h2>{{.}}</h2>{{/campaignDescription}}
```

## Campaign blocks

The `blocks` collection is a top-level [collection](/elevate/docs/addons/email-recommendations/product-templates/template-model#collection-extension) with campaign blocks. Each block has a set of [product positions](#product-positions), a [type](#type), and a [template name](#template-name).

### Blocks

#### Syntax

```handlebars icon="code" theme={null}
{{#blocks}} ... {{/blocks}}
```

#### Examples

```handlebars title="Iterate over all blocks" icon="code" expandable theme={null}
{{#blocks}}
    <div class="block">
        <!-- Print the code associated with the block type -->
        <!-- Should be set before for each possible type -->
        {{#store.byName}}{{type}}{{/store.byName}}
        {{#positions}}
            <div class="product">
                <a href="{{productLink}}">
                <img src="{{productImageDesktop}}"/></a>
            </div>
        {{/positions}}
    </div>
{{/blocks}}
```

```handlebars title="Select second block by index" icon="code" theme={null}
{{#blocks.idx.2}}
    <div class="second_block">
        ...
    </div>
{{/blocks.idx.2}}
```

### Type

Each block has its own type, which can be associated with a code block to enable customization.

#### Description

`TOP_SELLERS` — Recommends products according to their strategy score.

`CUSTOMER_BASED` — Recommends products based on the visitor's interest.

`PRODUCT_BASED` — Recommends products based on specified product sets.

`FAVORITE_BASED` — Recommends products based on products that a visitor has marked as a favorite.

```handlebars title="Map block title to the template type" icon="code" theme={null}
{{#store.put.CUSTOMER_BASED}}<div class='customer_based'>Special for you</div>{{/store.put.CUSTOMER_BASED}}

{{#blocks}}
    {{#store.byName}}{{type}}{{/store.byName}}
    ...
{{/blocks}}
```

```handlebars title="Map several values to one block type" icon="code" expandable theme={null}
{{#store.byName}}CUSTOMER_BASED : Special for you{{/store.byName}}
{{#store.byName}}blockStyle.CUSTOMER_BASED : main-recommendations{{/store.byName}}
{{#store.byName}}TOP_SELLERS : Popular with our customers{{/store.byName}}
{{#store.byName}}blockStyle.TOP_SELLERS : side-recommendations{{/store.byName}}

{{#blocks}}
<div class="{{#store.byName}}blockStyle.{{type}}{{/store.byName}}">
    <div class='block-title'>{{#store.byName}}{{type}}{{/store.byName}}</div>
    ...
</div>
{{/blocks}}
```

### Template name

If the campaign block has an associated template, the name of the template can be obtained.

#### Syntax

```handlebars title="Obtain the template name" icon="code" theme={null}
{{templateName}}
```

```handlebars title="Enter the block section if the template name is present" icon="code" theme={null}
{{#templateName}} ... {{/templateName}}
```

### Template description

If the campaign block has an associated template, the description of the template can be obtained.

#### Syntax

```handlebars icon="code" theme={null}
{{templateDescription}}
```

### Block position

The block position in the campaign, starting from 1.

#### Syntax

```handlebars icon="code" theme={null}
{{blockPosition}}
```

### Product positions

A [collection](/elevate/docs/addons/email-recommendations/product-templates/template-model#collection-extension) of product positions. This allows for getting product images and product page URLs.

#### Syntax

```handlebars icon="code" theme={null}
{{#positions}} ... {{/positions}}
```

#### Examples

```handlebars title="Generate product positions with mobile images" icon="code" theme={null}
{{#positions}}
    <div class="product-position">
        <a href="{{productLink}}"><img src="{{productImageMobile}}"/></a>
    </div>
{{/positions}}
```

```handlebars title="Table layout with a fixed number of columns" icon="code" expandable theme={null}
<tr>
{{#positions}}
    <td class="product-position">
        <a href="{{productLink}}"><img src="{{productImage}}"/></a>
    </td>
    {{^-last}}
        {{#cmp.intMod}}{{-index}}:3{{/cmp.intMod}}
        {{#cmp.testEq}}</tr><tr>{{/cmp.testEq}}
    {{/-last}}
{{/positions}}
</tr>
```

#### Product position

The position of a product in a block, starting from 1.

##### Syntax

```handlebars icon="code" theme={null}
{{position}}
```

#### Absolute product position

The absolute position of a product in the campaign, starting from 1. `{{-index}}` shows the position inside the collection, but `{{absolutePosition}}` shows the campaign block number.

##### Syntax

```handlebars icon="code" theme={null}
{{absolutePosition}}
```

#### Product link

A field with a link to the associated product page. For more information, see the [product URL template](/elevate/docs/addons/email-recommendations/base-configuration#product-url-template).

##### Syntax

```handlebars icon="code" theme={null}
{{productLink}}
```

#### Product image

Links to images made by the associated product image template.

##### Description

```handlebars title="The URL to the image for the selected template type, defaults to Desktop" icon="code" theme={null}
{{productImage}}
```

```handlebars title="The URL to the desktop image" icon="code" theme={null}
{{productImageDesktop}}
```

```handlebars title="The URL to the mobile image" icon="code" theme={null}
{{productImageMobile}}
```

## Mobile and desktop product images

There are two types of product templates: `Desktop` and `Mobile`. Each type can produce a different image for the same product. It can be [checked](#template-checks) if a campaign block has a template with a specific type or not. Each [product position](#product-positions) has three properties for image links: `productImage`, `productImageDesktop`, and `productImageMobile`.

The `productImage` field produces a link to the selected template type, which defaults to `Desktop`. A mobile template will be selected inside a [mobile](#mobile-section) section or inside a `withMobile` [filter](#template-filters) section.

### Mobile section

Code inside this section will produce mobile template links by default. If the template has no mobile template, the mobile link will lead to the desktop product image.

```handlebars title="Wrap into mobile section example" icon="code" theme={null}
{{#mobile}} ... {{productImage}} ... {{/mobile}}
```

### Template filters

Template filters allow for selecting only [blocks](#campaign-blocks) that do or don't have a specific template type. If a campaign version other than the most recent one is resent, it's possible that not all blocks will have a [product image template](/elevate/docs/addons/email-recommendations/product-templates/product-templates). As product images cannot be produced for blocks without a template, these blocks can be excluded.

#### Description

```handlebars title="Selects blocks with a mobile template" icon="code" theme={null}
{{#withMobile}} ... {{/withMobile}}
```

```handlebars title="Selects blocks with a desktop template" icon="code" theme={null}
{{#withDesktop}} ... {{/withDesktop}}
```

#### Examples

```handlebars title="Select only blocks without a mobile template" icon="code" theme={null}
{{^withMobile}} {{#blocks}}...{{/blocks}} {{/withMobile}}
```

```handlebars title="Select blocks with a desktop template" icon="code" theme={null}
{{#withDesktop}} ... {{/withDesktop}}
```

### Template checks

As with filters, checks can be made to find out if a template type is present. This allows merchandisers to decide what should be shown depending on whether a certain template type is present or not.

#### Description

```handlebars title="Checks if the block has a mobile template" icon="code" theme={null}
{{#hasMobile}} ... {{/hasMobile}}
```

```handlebars title="Checks if the block has a desktop template" icon="code" theme={null}
{{#hasDesktop}} ... {{/hasDesktop}}
```

```handlebars title="Checks if the block has any templates at all" icon="code" theme={null}
{{#hasTemplate}} ... {{/hasTemplate}}
```

Archived campaigns can contain blocks that have no templates.
