ProcessWire Fields and Templates Setup
Fields and templates are the foundation of any ProcessWire project. A field defines data type and storage method; a template is a set of fields plus an associated PHP rendering file. Properly designed field structure saves tens of hours in further development.
Creating Fields
Fields are created in Setup → Fields → Add New. Must specify:
-
Name — machine name (Latin,
_), used in code as$page->field_name - Type — data type
- Label — displayed in editor
Frequently used field types:
| Type | Storage | Application |
|---|---|---|
FieldtypeText |
VARCHAR | Short strings, titles |
FieldtypeTextarea |
TEXT | Long text without HTML |
FieldtypeTextareaLanguage |
TEXT (per lang) | Multilingual text |
FieldtypeImage |
separate table | Images with metadata |
FieldtypeFile |
separate table | Documents, PDF |
FieldtypePage |
INT / table | Relations between pages |
FieldtypeRepeater |
child pages | Repeating field groups |
FieldtypeOptions |
INT | Dropdown list |
FieldtypeCheckbox |
INT(1) | Boolean value |
FieldtypeInteger |
INT | Numbers |
FieldtypeFloat |
FLOAT | Decimal numbers, prices |
FieldtypeURL |
VARCHAR | Links |
FieldtypeDatetime |
INT (UNIX timestamp) | Date and time |
Configuring FieldtypePage (Relations)
When creating Page-type field, configure:
-
Derefence as —
Page(one page) orPageArray(multiple) - Parent — limit selection to child pages of specific parent
- Template filter — show only pages with specified template
// In code: single relation
echo $page->category->title;
// Multiple relation
foreach ($page->tags as $tag) {
echo "<span class='tag'>{$tag->title}</span>";
}
Creating Templates
Template is created in Setup → Templates → Add New. Process:
- Create PHP file in
/site/templates/my-template.php - Go to Templates → Add New — ProcessWire finds file automatically
- Add needed fields on Fields tab
- Configure Access (permissions)
- Configure URLs (allow/forbid child pages, URL suffix)
Advanced Tab
Important Advanced tab parameters:
- Page class — custom PHP class for pages of this template
-
Prepend/Append file — include
_init.phpand_main.php - Cache time — cache template output N seconds
-
Allow page numbers — allow
/page2,/page3in URL (needed for pagination)
Fieldset and Field Grouping
Fieldset (FieldtypeFieldsetOpen / FieldtypeFieldsetClose) groups fields visually in editor without affecting storage:
Adding fields to template order:
-
fieldset_seo_open— FieldtypeFieldsetOpen, label="SEO" -
meta_title— FieldtypeText -
meta_description— FieldtypeTextarea -
fieldset_seo_close— FieldtypeFieldsetClose
In page editor these fields collapse into "SEO" block.
Repeater: Repeating Groups
Repeater field type contains several child fields that editor can add/remove:
// Field features (Repeater with fields: icon, headline, text)
foreach ($page->features as $feature) {
echo "<div class='feature-card'>";
echo " <img src='{$feature->icon->url}' alt=''>";
echo " <h3>{$feature->headline}</h3>";
echo " <p>{$feature->text}</p>";
echo "</div>";
}
RepeaterMatrix (paid ProFields module) allows multiple block types in one field — like Flexible Content in ACF.
Export and Import Configuration
Field and template configuration can be exported via Setup → Export/Import or DatabaseBackups module. To move between environments use JSON export of templates:
# Backup structure (not data)
# Via RockMigrations module or manually via API:
php -r "
require '/var/www/site/index.php';
echo \$templates->get('product')->exportJSON();
" > product-template.json
RockMigrations module allows describing field and template structure in PHP code and apply changes reproducibly — like migrations in Laravel.







