Template Overrides#

While Formie's default templates suit most needs, you can of course roll your own templates, so you have total control over the form, field, layout and more.

We recommend reading the theming overview docs before getting started, for an explanation of template overrides compared to other methods of theming forms.

The great thing about Formie's custom templates is that it doesn't have to be all-or-nothing. You can choose to override a single template, or all. For instance, you might have very specific markup needs to a Dropdown field. You can override just the template for the dropdown field, and nothing else.

Form Templates#

To get started, navigate to FormieSettingsForm Templates and create a new template. Enable the Use Custom Template setting to be able to define a template directory for your custom templates to sit. For example, if your templates exist in templates/_forms, you would enter _forms.

Be sure to select a directory when setting the template path, as there are multiple templates Formie can override. You can look at the directory structure (opens new window) for more.

You can also use the Copy Templates setting when creating, which will copy all of Formie's default templates into the directory you've specified. That way, you're starting off with the templates Formie already uses as a basis for your custom templates.

You can't modify Formie's default Form Templates. Instead, you must create a new Form Template, and ensure your forms use that. This gives you the benefit of being able to easily manage multiple custom templates across your forms.

Before we dive in, it's worth taking the time to understand the structure of how templates go together.

We're using the .html extension here for clarity. You can use .twig or whatever you have set in your defaultTemplateExtensions (opens new window) for the actual files.

  • form.html
  • field.html
  • page.html
  • _includes/
    • label.html
    • submit.html
    • ...
  • fields/
    • address.html
    • agree.html
    • categories.html
    • date/
      • _calendar.html
      • _datepicker.html
      • ...
    • ...

Let's start with the top-level templates.

Check out the raw templates on Formie's GitHub (opens new window) - they'll be the most up to date.

Overriding Form Templates#

To override the form template, provide a file named form.html in your template directory.

Available Template Variables#

Field templates have access to the following variables:

VariableDescription
formA Form object, for the form instance this template is for.
submissionThe current Submission object this this form may or may not have.
renderOptionsA collection of Render Options.

Overriding Page Templates#

To override the page template, provide a file named page.html in your template directory.

Available Template Variables#

Field templates have access to the following variables:

VariableDescription
formA Form object that this field belongs to.
pageA Page object, for the page instance this template is for.
renderOptionsA collection of Render Options.

Overriding Field Wrapper Templates#

To override the field template, provide a file named field.html in your template directory. This is the wrapper template around all fields. You can also override individual field types' templates, rather than changing the template for every field, regardless of type.

Available Template Variables#

Field templates have access to the following variables:

VariableDescription
formA Form object that this field belongs to.
fieldA Field object, for the field instance this template is for.
handleThe handle of the field.
elementThe current Submission object this this form may or may not have.
renderOptionsA collection of Render Options.

Overriding Field Templates#

You'll notice the above structure includes the fields/ directory. Inside this directory are a mixture of folders and individual files, each representing a template that you're able to override.

First, you'll need to identify the template's name. It's derived from the PHP class name for the field, converted to a "kebab" string. For easy reference, you can use the below table.

Class NameTemplate
Addressaddress.html
Agreeagree.html
Calculationscalculations.html
Categoriescategories.html
Checkboxescheckboxes.html
Datedate.html
Dropdowndropdown.html
Emailemail.html
Entriesentries.html
FileUploadfile-upload.html
Groupgroup.html
Headingheading.html
Hiddenhidden.html
Htmlhtml.html
MultiLineTextmulti-line-text.html
Namename.html
Numbernumber.html
Passwordpassword.html
Paymentpayment.html
Phonephone.html
Productsproducts.html
Radioradio.html
Recipientsrecipients.html
Repeaterrepeater.html
Sectionsection.html
Signaturesignature.html
SingleLineTextsingle-line-text.html
Summarysummary.html
Tabletable.html
Tagstags.html
Usersusers.html
Variantsvariants.html

Adding a template file in your specified template directory will use that template file over the ones Formie provide.

You might also have noticed we've shown date in a folder. Due to how Twig resolves templates, the below are equivalent:

fields/date.html - Is the same as - fields/date/index.html

For complex fields that have multiple templates, we've used folders to organise multiple templates in a single folder. You're welcome to follow this same pattern, but you're not forced to.

For example, the Date field, has the following templates in a folder:

  • fields/date/_calendar.html
  • fields/date/_datepicker.html
  • fields/date/_dropdowns.html
  • fields/date/_inputs.html
  • fields/date/index.html

This is because the date field has many display configurations. If you want to override the templates for this field, you just need to alter the index.html file. You can use the includes (denoted by _), or you don't have to.

Overriding Partials#

You'll have noticed in our preview of the templates' directory, the inclusion of an _includes directory. This houses partial templates that are used throughout the templates. This helps not only with re-use, but keeps things modular, which has a flow-on effect when you want to override just a partial.

The form.html file sets up your form, but also includes other partials like _includes/page-tabs.html, _includes/progress.html and _includes/submit.html. Rather than overriding the form.html file just to alter any one of these partials, you can override just the partial.

For example, let's say we want to override the page tabs of a multi-step form. We could create a file _includes/page-tabs.html and add our content to this template. There's no need to override form.html now!

How it Works#

Formie's templates use a custom Twig function like {{ formieInclude('_includes/page-tabs') }}. This is in contrast to what you might be used to in your own templates, something like {% include '_includes/page-tabs' %}. The drawback with this latter approach is how Formie resolves the template partial. Using {% include %} it will expect to find the template partial relative to the template file you're including it from. Instead, formieInclude() will resolve the template partial to either your overrides' folder, or Formie's default templates.

Previous ← Theme Config Next Custom Rendering →