Attributes
Note
Create your own columns of the database table as attributes and configure them
To create the attribute columns in the mm_* table, run a DB migration — see schema manager
Introduction
The “Attributes” component is one of the most fundamental settings in a MetaModel.
Attributes are used to define your own specific data fields and create them as columns in the
database table. On the page Storing Data Types as Attributes you can see which attribute
can be used for which database data type. In addition to the usual data types such as varchar,
int, text, etc., there are also attributes for special storage — more about this in the
following overview.
When creating an attribute “
New attribute”, the mandatory fields are the selection of
the attribute type and the entry of the column name — the column name defines, as the name
suggests, the label of the column in the database table. As additional inputs, a name and a
description can be filled in, which also appear as label and description in the input form.
Warning
When changing the attribute type, as well as when deleting the attribute, the previously entered values in the database will be deleted! If an attribute type must be changed while retaining the values, this should be accompanied directly at the database level, e.g. via export/import of the attribute column via CSV. A changed attribute should then be added again in the render settings and input forms.
See also
Checklist for changing an attribute type: Attribute Not Displayed After Change
Depending on the attribute type, further input options and settings become available after reloading the page. The following is a list of attribute types with notes on specific options:
Alias: Alias field, e.g. for URL parameters during filtering
The alias can be created as a combination of various (existing) attributes; as an option, the recreation of the alias when the source attributes change can be forced (force alias recreation); an alias is not automatically created as a unique value — for that, the “Unique values” checkbox must be activated — more…Checkbox: single checkbox for boolean values
The checkbox can be used to set boolean values (0|1); a special variant is “publish” — this displays the “eye” icon in the backend, but the filter for the publishing itself must be created manually; the column name “published” is generally used for the publication value; the “Listview checkbox” option allows a custom icon in the backend to display the status — more…Combined values: combination of various attributes
All existing attributes and “system attributes” such as ID, PID, etc. can be combined into a new attribute; the combination is done using sprintf formatting; e.g. the two attributes “Last name” and “First name” can be combined via “%s, %s” to “Last name, First name”; the “Force update” option forces recreation when values change — more…Country: country selection
This attribute provides a country selection; the selection of countries can be narrowed with the “Filter available countries” option — more…Decimal: decimal numbers
This attribute is for storing decimal numbers such as monetary amounts; it has two decimal places — more…File: file picker
The “File” attribute provides a file picker for selecting a file or, if the “Multiple selection” option is set, multiple files; additional file options can be set during selection with the “Customize the file tree” option; when using with images, note that for (direct) display of preview images in the backend or frontend, the “Use as image field with preview image” option in the render settings of the file attribute must be set — more…Language code: selection of ISO language codes
This attribute provides a selection of language codes; the language codes can be selected via checkbox — more…Long text: text input
Attribute for longer text input — more…Numeric: input of integer values — more…
Single select [select]: relation (1:n) to another MetaModels or Contao table
The “Select” attribute creates a 1:n relation to another table; this can be either a MetaModels table or any other Contao table, e.g. tl_member — more…Table text: input of values as a table
The “Table text” attribute defines a number of columns including column label and column width; any number of rows can then be created in the input form, e.g. to store multiple URLs or phone numbers — more…Multi-select [tags]: relation (m:n) to another MetaModels or Contao table
The “Tags” attribute creates an m:n relation to another table; this can be either a MetaModels table or any other Contao table, e.g. tl_page; the relation is resolved in a special MetaModels table, so no column is created in the MetaModel table for this attribute — more…Text: simple text field — more…
Timestamp: date or date and time
Data is stored as a Unix timestamp; conversions may need to be made for custom SQL filters — more…URL: link text and URL
Entry of external links (include “http://”) or internal links via the page picker; optionally, “Remove title” can output only the URL — more…Token (from MM 2.4): unique string
Creates unique strings that do not change again — more…
If the “Translation” option is activated in the MetaModel, the following attributes are additionally available for multilingual support:
Translated checkbox — more…
Translated combined values — more…
Translated file — more…
Translated long text — more…
Translated select — more…
Translated table text — more…
Translated tags — more…
Translated text — more…
These attributes differ from their monolingual counterparts essentially through the entry of multilingual data for name and description. Special extension tables are used for translated attributes, not the table created by the MetaModel.
Note that for relations via “Single select” or “Multi-select” between two MetaModels with translations, it is generally not necessary to select “Translated single select” or “Translated multi-select”. MetaModels automatically handles language detection and switching with the “Single select” and “Multi-select” attributes.
The two “translated variants” are mainly intended for connecting to tables that do not belong to MetaModels and have a separate field for the language variant — or for the special case where different items should be selected in the referenced MetaModel depending on the language. More on this on a special page about multilingual support — sponsors sought!
In addition to the listed attributes, further attribute types may also be available via additional MetaModels extensions. The attributes are installed via Composer or like normal Contao extensions by copying to the “modules” folder (depending on how they are provided by the developer).
Examples of additional attributes are:
Rating: rating module with stars
The attribute module is used to output a “star rating” in the frontend; various options such as the number of stars, etc. can be set in the backend — more…Color picker: selection of web colors and transparency — more…
Levenshtein: word search by Levenshtein
The attribute calculates word similarity for flexible search — more…Country selection: selection list with countries — more…
Content article: possibility to create Contao content elements similar to an article in
a widget — also available as translated variant — more…Multi-table: similar to “Table text” attribute but each “cell” can have its own
widget type such as select, radio buttons, checkboxes, etc. — also available
as translated variant — more…Geo-distance: calculates the geographic distance to the search point for a perimeter search
The value can be used to sort lists by distance — more…
The order in which attributes are created is freely selectable — only for attributes that refer to other attributes, such as “Alias” or “Combined values”, a subsequent creation makes sense.
For the “Select” and “Multi-select” attributes, the MetaModels to be referenced must also be created first.
Options
Two options are available for all attributes: “Override variants” and “Unique values”.
“Override variants” makes the attribute available in the input forms for variant entry. The prerequisite for this is that the “Variants” option is set in the MetaModel — otherwise the checkbox is inactive.
The “Unique values” option checks attribute inputs for uniqueness.
Procedure
A new attribute is created via “
New attribute”. After all necessary options have
been entered or selected, the setting is saved and appears in the attribute list of the
existing MetaModels. The order in the list has no further influence.
Run the database migration!
See also
In the cookbook:
Details of All Attributes
- Alias
- Checkbox
- Combined Values
- Content of an Article
- Country
- Decimal
- File
- Language Code
- Long Text
- Numeric
- Single Select [select]
- Table Text
- Table Multi (MCW)
- Multi-Select [tags]
- Text
- Timestamp
- Token (from MM 2.4)
- URL
- Translated Alias
- Translated Checkbox
- Translated Combined Values
- Translated Content of an Article
- Translated File
- Translated Long Text
- Translated Single Select [select]
- Translated Table Text
- Translated Multi-Table (MCW)
- Translated Multi-Select [tags]
- Translated Text
- Translated URL
- Color Picker
- Geo Distance
- Levenshtein
- Rating