The following Twig functions are available to call in your Twig templates.
craft.formie.forms(query)#See Form Queries
{% set form = craft.formie.forms({ handle: 'contactForm' }).one() %}
craft.formie.submissions(query)#{% set submissions = craft.formie.submissions({ formId: 123, limit: 10 }).all() %}
craft.formie.renderForm(form, options = {})#Renders the entire form, taking into account custom Form Templates. The form parameter can be a Form object, or the handle of a form. For details on the options you can pass into the options parameter, see Render Options.
{{ craft.formie.renderForm('contactForm') }}
craft.formie.renderPage(form, page)#Renders a single page, taking into account custom Form Templates. This will also include captchas (if enabled) and submit button(s).
{% set form = craft.formie.forms({ handle: 'contactForm' }).one() %}
{% for page in form.getPages() %}
{{ craft.formie.renderPage(form, page) }}
{% endfor %}
craft.formie.renderField(form, field)#Renders a single field, taking into account custom Form Templates.
{% set form = craft.formie.forms({ handle: 'contactForm' }).one() %}
{% for field in form.getCustomFields() %}
{{ craft.formie.renderField(form, field) }}
{% endfor %}
craft.formie.registerAssets(form, options = {})#Used to specifically register the CSS and JS for a form. Takes the same arguments as craft.formie.renderForm. This is particular useful for Cached Forms or Custom Rendering.
{% do craft.formie.registerAssets('contactForm') %}
craft.formie.renderFormCss(form)#Allows specific placement of a form's CSS on the page. Takes the same arguments as craft.formie.renderForm.
{{ craft.formie.renderFormCss('contactForm') }}
<div class="form-wrap">
{{ craft.formie.renderForm('contactForm') }}
</div>
craft.formie.renderFormJs(form)#Allows specific placement of a form's JS on the page. Takes the same arguments as craft.formie.renderForm.
<div class="form-wrap">
{{ craft.formie.renderForm('contactForm') }}
</div>
{{ craft.formie.renderFormJs('contactForm') }}
craft.formie.renderCss(inline)#Renders the Formie base and theme CSS. Useful for SPA or lazy loading, where you load forms on-demand. As such, it should only be included one per page.
<head>
{{ craft.formie.renderCss(true) }}
</head>
<body>
<div class="form-wrap">
{{ craft.formie.renderForm('contactForm') }}
</div>
</body>
craft.formie.renderJs(inline)#Renders the Formie JavaScript (formie.js) file. Useful for SPA or lazy loading, where you load forms on-demand. As such, it should only be included one per page.
<head>
{{ craft.formie.renderJs(true) }}
</head>
<body>
<div class="form-wrap">
{{ craft.formie.renderForm('contactForm') }}
</div>
</body>
craft.formie.setRenderVariables(mixed)#Sets any render variables to be globally available to Formie for rendering.
This should be included before a craft.formie.renderForm() call.
{{ craft.formie.setRenderVariables({
scriptAttributes: {
nonce: 'my-nonce',
},
}) }}
{{ craft.formie.renderForm('contactForm') }}
craft.formie.getFieldOptions(field)#Returns a field's render options from the main options array.
craft.formie.getLabelPosition(field)#Returns the label position for a field.
{% set labelPosition = craft.formie.getLabelPosition(field, form) %}
{% if labelPosition.shouldDisplay('above') %}
<label>...</label>
...
craft.formie.getLabelPosition(field)#Returns the label position for a field.
{% set labelPosition = craft.formie.getLabelPosition(field, form) %}
{% if labelPosition.shouldDisplay('above') %}
<label>...</label>
...
craft.formie.getInstructionsPosition(field)#Returns the instructions position for a field.
{% set instructionsPosition = craft.formie.getInstructionsPosition(field, form) %}
{% if instructionsPosition.shouldDisplay('below') %}
<small>...</small>
...
craft.formie.getParsedValue(value, submission)#For parsing a variable-string against a submission. For example, you might have a field with a handle emailAddress, and you could use the string {emailAddress} and a supplied submission to swap the template tag with the content from a submission.
{% set toEmail = craft.formie.getParsedValue('Send me an email to {emailAddress}', submission) %}
craft.formie.setCurrentSubmission(form, submission)#Sets the current submission for a particular form. This is mostly used for multi-page forms.
craft.formie.populateFormValues(handle, values, force = false)#Populates the defaultValue of a field for a form. Note that this should be done before rendering the form. See Populating Forms.
{# Sets the field with handle `text` to "Some Value" for the form with a handle `contactForm` #}
{% do craft.formie.populateFormValues('contactForm', { text: "Some Value" }) %}
{# or use a `form` object #}
{% set form = craft.formie.forms({ handle: 'contactForm' }).one() %}
{% do craft.formie.populateFormValues(form, { text: "Some Value" }) %}
{# Must be done before the `renderForm()` #}
{{ craft.formie.renderForm('contactForm') }}