<p>You need to let Twig interpret the variable as a string. This works for me: </p>

<pre><code>{% set theForm = entry.formSelect %}
{% include ''~theForm~'' %}
</code></pre>

<p>Hope this helps!</p>

CC BY-SA 3.0
2015-03-12T19:50:38.840Z
2015-03-12T19:50:38.840Z
Aaron Berkowitz
<p>I am trying to use a variable, based on an entry field, to load a form with a Twig include. The code is pretty straightforward:</p>

<pre><code>{% set theForm = entry.formSelect %}
{% include theForm %}
</code></pre>

<p>Doing this throws this error:</p>

<blockquote>
  <p>Undefined property: Craft\SingleOptionFieldData::$cacheKey</p>
</blockquote>

<p>If I print the variable, it looks exactly as you would expect, e.g. forms/_basic</p>

<p>Any suggestions would be appreciated!</p>

CC BY-SA 3.0
2015-03-12T19:21:45.887Z
maybe try `entry.formSelect.value`?
Marion Newlevant
<templating><include>
Using a variable with Twig include
# Using a variable with Twig include

(Asked by: username_0 on 2015-03-12)

I am trying to use a variable, based on an entry field, to load a form with a Twig include. The code is pretty straightforward:
{% set theForm = entry.formSelect %}
{% include theForm %}

Doing this throws this error:

Undefined property: Craft\SingleOptionFieldData::$cacheKey

If I print the variable, it looks exactly as you would expect, e.g. forms/_basic
Any suggestions would be appreciated!

**Tags:** templating, include

> **Comments:**
> **username_1**: maybe try `entry.formSelect.value`?  

---

## 1 answers

### Answer by username_2 on 2015-03-12. Score: 3

You need to let Twig interpret the variable as a string. This works for me: 
{% set theForm = entry.formSelect %}
{% include ''~theForm~'' %}

Hope this helps!


---

