Skip to content

Step 4 - Introduce a template

Tip

You can find all files used and modified in this step on GitHub.

Point 2D template

In order to display data from the Field Type, you need to create and register a template for it. Each Field Type template receives a set of variables that can be used to achieve the desired goal. In this case the most important variable is the field, an instance of eZ\Publish\API\Repository\Values\Content\Field. In addition to its own metadata (id, fieldDefIdentifier, etc.), it exposes the Field Value through the value property.

Remember that Field Type templates can be overridden in order to tweak what is displayed and how. For more information, see the documentation about Field Type templates.

First, create a point2d_field.html.twig template in the templates directory. It will define the default display of a Point 2D. Your basic template for Point 2D should look like this:

1
2
3
{% block point2d_field %}
    ({{ field.value.getX() }}, {{ field.value.getY() }})
{% endblock %}

Template mapping

Next, provide the template mapping in config/packages/ezplatform.yaml:

1
2
3
4
5
6
ezplatform:
    system:
        default:
            # ...
            field_templates:
                - { template: 'point2d_field.html.twig', priority: 0 }