<p>This could potentially be handled a few different ways...</p>
<p><strong>1. Move the Form Title location</strong></p>
<p>Remove the Title from the formatting template and set up your main template loading the form to look something like this:</p>
<pre><code>{% set form = craft.freeform.form('myForm')  %}

{% if showFormTitle %}
   {{ form.name }}
{% endif %}

{{ form.render }}
</code></pre>
<p><strong>2. Wait for Freeform 3.12</strong></p>
<p>Freeform 3.12 will be going into beta very soon and will have the ability to add something like this to the form payload:</p>
<pre><code>{{ form.render({ showFormTitle: true }) }}
</code></pre>
<p>And in your formatting template, use:</p>
<pre><code>{% if form.properties.showFormTitle %}
   {{ form.name }}
{% endif %}
</code></pre>
<p><strong>3. Use Conditional Rules feature</strong></p>
<p>You could use a combination of using the <code>overrideValues</code> parameter, Conditional Logic, and an HTML field with Twig parsing on.</p>
<ol>
<li>Go to the form builder for this form.</li>
<li>Add an HTML field.</li>
<li>Add the value <code>{{ form.name }}</code> and any other formatting to the HTML block field.</li>
<li>Check off the <strong>Allow Twig</strong> checkbox.
<ul>
<li>If you don't see this option, be sure to upgrade to the latest version of Freeform and go to the <em>Form Builder Settings</em> area (Freeform -&gt; Settings -&gt; Form Builder Settings) and enable the <strong>Allow Twig to be Enabled for each HTML block?</strong> toggle.</li>
</ul>
</li>
<li>Create a hidden field (for purpose of this example, let's give it a handle of <code>showTitleField</code>).</li>
<li>Go to the Conditional Rules tab in the form builder and add some logic for this. Something like: Show the HTML field only when <code>showTitleField</code> contains a value of <code>show</code>.</li>
<li>Save the form.</li>
<li>In your templates, where you call the form, add the <code>overrideValues</code> parameter and add a line for the hidden field. Something like:
<pre><code>overrideValues: {
   showTitleField: &quot;show&quot;
}
</code></pre>
<ul>
<li>If you need to do something dynamic with that value, you can check out the guide here for <a href="https://docs.solspace.com/craft/freeform/v3/guides/passing-dynamic-data-to-forms.html" rel="nofollow noreferrer">Passing Dynamic Data to Forms</a>.</li>
</ul>
</li>
</ol>

CC BY-SA 4.0
2021-08-24T10:24:16.230Z
Wow. That's, uhh, quite a workaround! If I'm understanding it correctly, that's shifting the onus of rendering the form name from the formatting template itself, on to an HTML field _inside_ the form. While quite imaginatave, this isn't practical for the use-case I have as the title and the form fields are somewhat separated, HTML-wise. Also, it's a complex-enough solution that I might as well just clone the formatting template, minus the code for the form title. :-/ Might I submit the ability to pass Twig variables to formatting templates as a feature request? ;)
Sandwich
CC BY-SA 4.0
2021-08-24T15:22:35.627Z
The other option you have would be rather simple... see next answer...
Solspace
CC BY-SA 4.0
2021-08-24T15:29:13.793Z
@Sandwich I have updated the answer to include some other options.
Solspace
CC BY-SA 4.0
2021-08-24T15:35:10.193Z
I see that! Option 1 is of course a very simple and sensible solution, however on a site that already has numerous forms scattered about on various pages, it's probably more work than it's worth. Option 2 sounds good, though! Might I suggest the ability to somehow override the form title, not just show or hide it? Perhaps `overrideValues: { name: "Custom Form Title" }`, or perhaps `{{ form.render({ formTitle: [true|false|"Custom Title"] }) }}` ?
Sandwich
CC BY-SA 4.0
2021-08-24T17:28:44.040Z
Sure, I'll make a note about that for FR list - thanks! :)
Solspace
CC BY-SA 4.0
2021-12-21T16:16:51.260Z
I've got version 3.12.9.1. The code `{{ craft.freeform.form(entry.formField.handle,  formRenderSettings).render({ formTitle: 'hidden' }) }}` results in the error `Neither the property "properties" nor one of the methods "properties()", "getproperties()"/"isproperties()"/"hasproperties()" or "__call()" exist and have public access in class "Solspace\Freeform\Library\Composer\Components\Form" in "__string_template__8dd7283256bc9c330b24d64d52715d2f1c033f64b05cb712c143bff47665e451" at line 19.`
Sandwich
CC BY-SA 4.0
2021-12-22T17:34:28.387Z
Sorry @Sandwich, I can see it isn't working correctly either. We'll look into it and get a fix out tomorrow. :)
Solspace
CC BY-SA 4.0
2021-12-23T17:52:17.533Z
@Sandwich, this should now be fixed in Freeform 3.12.11. :)
Solspace
CC BY-SA 4.0
2021-08-23T15:01:54.213Z
2021-08-24T15:28:26.263Z
2021-08-24T15:28:26.263Z
Solspace
<p>I want to be able to toggle the display of a form's Title on or off, without having to resort to using a mostly-identical copy of the formatting template.</p>
<p>Freeform formatting template:</p>
<pre><code>{% if showFormTitle %}{{ form.name }}{% endif %}
</code></pre>
<p>How can I control the value of <code>showFormTitle</code> from the Twig template that renders the form? This (and all the permutations of it that I've tried) doesn't work:</p>
<pre><code>{% set showFormTitle = true %}
{{ craft.freeform.form(myForm).render() }}
</code></pre>
<pre><code>{% set showFormTitle = true %}
{{ craft.freeform.form(myForm).render() with { showFormTitle: showFormTitle } }}
</code></pre>

<templating><plugin-freeform>
How can I pass a variable to Freeform's formatting template so that it's available to Twig?
# How can I pass a variable to Freeform's formatting template so that it's available to Twig?

(Asked by: username_0 on 2021-08-23)

I want to be able to toggle the display of a form's Title on or off, without having to resort to using a mostly-identical copy of the formatting template.
Freeform formatting template:
{% if showFormTitle %}{{ form.name }}{% endif %}

How can I control the value of showFormTitle from the Twig template that renders the form? This (and all the permutations of it that I've tried) doesn't work:
{% set showFormTitle = true %}
{{ craft.freeform.form(myForm).render() }}

{% set showFormTitle = true %}
{{ craft.freeform.form(myForm).render() with { showFormTitle: showFormTitle } }}

**Tags:** templating, plugin-freeform

---

## 1 answers

### Answer by username_1 on 2021-08-23. Score: 3 | Accepted answer

This could potentially be handled a few different ways...
1. Move the Form Title location
Remove the Title from the formatting template and set up your main template loading the form to look something like this:
{% set form = craft.freeform.form('myForm')  %}

{% if showFormTitle %}
   {{ form.name }}
{% endif %}

{{ form.render }}

2. Wait for Freeform 3.12
Freeform 3.12 will be going into beta very soon and will have the ability to add something like this to the form payload:
{{ form.render({ showFormTitle: true }) }}

And in your formatting template, use:
{% if form.properties.showFormTitle %}
   {{ form.name }}
{% endif %}

3. Use Conditional Rules feature
You could use a combination of using the overrideValues parameter, Conditional Logic, and an HTML field with Twig parsing on.

Go to the form builder for this form.
Add an HTML field.
Add the value {{ form.name }} and any other formatting to the HTML block field.
Check off the Allow Twig checkbox.

If you don't see this option, be sure to upgrade to the latest version of Freeform and go to the Form Builder Settings area (Freeform -> Settings -> Form Builder Settings) and enable the Allow Twig to be Enabled for each HTML block? toggle.


Create a hidden field (for purpose of this example, let's give it a handle of showTitleField).
Go to the Conditional Rules tab in the form builder and add some logic for this. Something like: Show the HTML field only when showTitleField contains a value of show.
Save the form.
In your templates, where you call the form, add the overrideValues parameter and add a line for the hidden field. Something like:
overrideValues: {
   showTitleField: "show"
}


If you need to do something dynamic with that value, you can check out the guide here for Passing Dynamic Data to Forms.

> **Comments:**
> **username_0**: Wow. That's, uhh, quite a workaround! If I'm understanding it correctly, that's shifting the onus of rendering the form name from the formatting template itself, on to an HTML field _inside_ the form. While quite imaginatave, this isn't practical for the use-case I have as the title and the form fields are somewhat separated, HTML-wise. Also, it's a complex-enough solution that I might as well just clone the formatting template, minus the code for the form title. :-/ Might I submit the ability to pass Twig variables to formatting templates as a feature request? ;)  
> **username_1**: The other option you have would be rather simple... see next answer...  
> **username_1**: @Sandwich I have updated the answer to include some other options.  
> **username_0**: I see that! Option 1 is of course a very simple and sensible solution, however on a site that already has numerous forms scattered about on various pages, it's probably more work than it's worth. Option 2 sounds good, though! Might I suggest the ability to somehow override the form title, not just show or hide it? Perhaps `overrideValues: { name: "Custom Form Title" }`, or perhaps `{{ form.render({ formTitle: [true|false|"Custom Title"] }) }}` ?  
> **username_1**: Sure, I'll make a note about that for FR list - thanks! :)  
> **username_0**: I've got version 3.12.9.1. The code `{{ craft.freeform.form(entry.formField.handle,  formRenderSettings).render({ formTitle: 'hidden' }) }}` results in the error `Neither the property "properties" nor one of the methods "properties()", "getproperties()"/"isproperties()"/"hasproperties()" or "__call()" exist and have public access in class "Solspace\Freeform\Library\Composer\Components\Form" in "__string_template__8dd7283256bc9c330b24d64d52715d2f1c033f64b05cb712c143bff47665e451" at line 19.`  
> **username_1**: Sorry @Sandwich, I can see it isn't working correctly either. We'll look into it and get a fix out tomorrow. :)  
> **username_1**: @Sandwich, this should now be fixed in Freeform 3.12.11. :)  

---

