Template functions

The data structure set of any given product can be quite complex. The obscurity of attribute types, nested scopable and localizable values.

In this part I will explain what the defaults are, and, how you can feed or overrule this by supplying more context.

Normalization

The normalizer will render product data values by using the linked template context.

{{ normalize('attribute_code', 'context', 'productData') }}

Parameters

name type required
attribute_code string Y
context array N overrules the linked template context
productData array N overrules the linked product data

Global attribute

Global attribute values are the easiest to render, no locale is given.

{
    'storage': [{
        locale: null,
        scope: null,
        data: {
            'unit': GIGABYTE,
            'amount': 64
    }]
}

result : 64 GIGABYTE

{{ normalize('storage', {'map': ['GIGABYTE': 'GB']}) }}

result : 64 GB

Scopable attribute

{
    'description': [
    {
        locale: null,
        scope: nl_BE,
        data: 'dutch description'
    },
    {
        locale: null,
        scope: fr_BE,
        data: 'french description'
    }
    ]
}
 
 
# relevant template context
{
    'locale': 'nl_BE'
}
{{ normalize('description') }}

result : dutch description

{{ normalize('description', {'locale': 'fr_BE'}) }}

result : french description

Attributes with code references

Akeneo has a couple of attribute types that have code values.

The PDF generator will always normalize these attribute types to the label assigned to the code reference.

# example

{
    'color': [
    {
        locale: null,
        scope: null,
        data: 'red'
    }
}
 
 
# relevant template context
{
    'locale': 'nl_BE'
}

result : Rood

the value comes from the attribute label option, it’s part of a transformation flow, more here TODO

Summarize

Summarize is a function that will inherit all of it’s options from normalize but with the attribute codes comma separated.

If the attribute holds no value it will not be rendered.

your attributes will share the same context, so if you need to specify context per attribute use the group function instead.

Parameters

name type required
attribute_codes comma separated list Y
context array N overrules the linked template context
productData array N overrules the linked product data

Context

name default
separator ', ' define your separator

Group

Grouping is nothing more then a list presenter of specific attributes.

Group function will only render actual values in a separated list.

You can supply as many values as you want.

Parameters
name type required
attribute_codes comma separated list Y
Value1 string N
Value2 string N
Value … string N
Context
name default
separator ', ' define your separator
Example
group(
    ', ',
    normalize('screensize_inch', {'separator': ', ', 'map': mapping}, item),
    normalize('screen_resolution_pix', {'format': '%value% pixels'}, item)
)

In this example we see 2 distinct attributes from a different type that require specific context.

Translation

This function fetches a translation that you have defined in the translation section.

You don’t need to provide any Locale context as context is already provided to the template itself.

Also attribute Labels will we fetched if no translation is found, just provide the attribute_code instead of the translation_code.

The translations will be collected from the data inside the pdf-values.

{{ trans('translation_code') }}

Combining functions

You are able to combine functions

{{ aws(normalize('image')) }}