pixolino Templates: DataSets (Public BETA)
With DataSets your editors are able to manage self defined datasets and include them into their web pages (multiple times if required).
Fields
A DataSet consists of various field types, which can be added and sorted in the DataSet menu:
- Plain text (API field type 1)
- Formatted text (with Rich Text Editor, API field type 2)
- Email address (API field type 4)
- Number (API field type 6)
- URL (API field type 8)
- Image (API field type 9)
- File (API field type 7)
- Select (from given options, API field type 3)
- Date (API field type 10)
- Date with time (API field type 11)
Templates for website output
After adding a new DataSet field an unique code is generated, which can be referred to in the template code. This code is part of at least one specialized subtemplate.
When generating your subtemplate chose “DataSet” as purpose to ensure your editors may select this subtemplate in PageObject “DataSet”.
Subtemplates with the purpose “DataSet” may not contain slot definitions.
Accessing data within a template
The data is available in an array “datasets” which contains objects. Using the unique code (within the scope of the single dataset object) of your fields as keys, you have access to the data of each dataset.
You may use Twig to iterate over the data fields of your datasets:
{% for dataset in datasets %}
…
{% endfor %}
Accessing a field inside this loop is easy: Just use the unique key which has been created during saving your field (and is referenced in the administration section of each DataSet).
Example: Accessing a field with unique key “field_1”:
{{ dataset.field_1 }}
Special handling for fields containing HTML (as provided by the Rich Text Editor)
pixolino escapes HTML tags by default to prevent XSS hacking. If you need unescaped HTML output, you have to add the “raw” filter to your field variable.
{{ dataset.field_1|raw }}
Special handling for Date and DateTime fields
pixolino delivers Date and DateTime as twig date objects. It's your choice how to render the underlying date/time informations using the “date” filter.
{{ dataset.field_1|date("m/d/Y") }}
Checking if a field contains data
If you are not sure wether your field exists (and is not empty!), you may check it's existance first. This is always best practice, as the field definition of a DataSet may change over time – even for once required fields!
{% if dataset.field_1 is defined %}
{{ dataset.field_1 }}
{% endif %}
Accessing images and files
For uploaded images and files the returned field value is the absolute path to the file. You may use this as src or href attribute.
<img src="{{ dataset.field1 }}">
In the above example, the alt attribute of the img tag could be filled with the value of a text field:
<img src="{{ dataset.field1 }}" alt="{{ dataset.field2 }}">