This is a Developer task |
Fields templates determine how a field’s value is displayed on your website. For more information on how field templates are used in OpenCities, please see our overview of the OpenCities framework.
Create or edit a field template
All fields have a default template to start with. We strongly recommend that you don’t edit this template. If you want to change the template of a field, create a new template instead. For each field, you can have any number of field templates.
To create or edit a field template:
- Go to More > Fields and create a new field or select an existing one.
- Switch to the Templates tab.
- Click Create New or select an existing template. If you’re editing a System Field, you can’t edit any of its existing OpenCities templates - you have to create a new one.
- Fill in the different parts of your template. Keep reading to find out more about each part.
There are 4 template parts you can edit (5 for Date fields). Each part can have HTML, text, or references to other fields. When the markup is generated, the different template parts are combined like this:
Template name
A template name which is unique within the selected field.
Template header text
The header text is displayed once at the top when the field has a value.
Template text
Template text displays once for single value fields such as Textbox, Textarea, WYSIWYG, Drop Down List, Radio button List, etc. The text displays multiple times for multi-value fields such as Check box List, List hyperlink, etc.
For a date field, template text is used for single date, multi date, and recurring dates.
Alternate template
An alternate template is a special template only available for Date fields. It’s used for values entered as a time span. This is so you can have an alternate template for the start date and end date, or different dates.
Property
You will get unique options for the property based on the field type.
Template footer text
The footer text is displayed once at the bottom when the field has a value.
Empty template text
Empty template text is rendered once when the field doesn’t have a value. When this is shown, the header, footer, template text and alternate template will not be displayed.
Save your template when you’re done.
Copy a field template
If you want to create a variation of an existing template or use a similar template in another field, use the copy template feature. You can copy a template from one of your custom fields or even copy from an existing OpenCities field.
- Go to More > Fields and select an existing template.
- Switch to the Templates tab.
- Select the template you want to copy.
- At the bottom of the page, choose the field you want to copy the template to from the drop down. If you want to make a copy within the same field, choose the current field.
- Press Copy.
What's next?
If you're happy with its template, add the field to a content type so you can start using it to build pages.