Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-03-12T19:50:38.840Z
Answers.LastActivityDate: 2015-03-12T19:50:38.840Z
Answers.UserDisplayName: Aaron Berkowitz
Body: <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>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-03-12T19:21:45.887Z
Comments.Text: maybe try `entry.formSelect.value`?
Comments.UserDisplayName: Marion Newlevant
Tags: <templating><include>
Title: Using a variable with Twig include
ThreadText: # 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!
  
  
  ---
  
  