New: Learn Statamic on Laracasts!

We've retired the forum in favor of GitHub Discussions.

New conversations can be started on GitHub. Existing conversations will remain for a while longer.

Head over to GitHub →

Use variable inside an {{ if ... }}

Frederik Heyninck May 8, 2019 by Frederik Heyninck

Hi

I want to do something like this:

{{ if (old:{{tax:form_field}} | in_array:title) }} checked {{ /if }}

The form_field part is a dynamic variable from a taxonomie, but it throws an error. I tried the following but does not work:

{{ if (old:tax:form_field | in_array:title) }} checked {{ /if }}

This is my whole code part:

{{ taxonomy:prijsaanvraag scope="tax"  }}
            <h4>{{ tax:title }}</h4>
            <ol>
          {{ collection  }}
            <li> 
              <input type="checkbox" name="{{ tax:form_field }}[]" id="{{ slug }}" value="{{ title }}" {{ if (old:{{tax:form_field}} | in_array:title) }} checked {{ /if }}>
              <label for="{{ slug }}">{{ title }} </label>
            </li>
          {{ /collection }}
          </ol>
      {{ /taxonomy:prijsaanvraag }}
Answered by Erin Dalzell!
>>>>>>> Answered <<<<<<<
2 Replies
2 Followers