1

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!

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!

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.