Home Forums Front-end Issues checkbox fn('get_field') return as array


checkbox fn('get_field') return as array

  • I am trying to use timber twig to call out the acf value, one of the field type is checkbox and select multiple value, however when i use get_field, it returns as array instead of multiple values, tried get_fields return as null.

    code as following

    <tr class="field_tr">
    {% if fn('get_field', 'university') is not empty %}
    <td class="field_title"><strong>{{ __('University', 'realtyspace') }}</strong></td>
    <td class="field_value">{{ fn('get_field', 'university') }}</td>			  
     {% endif %}

    how do i call out multiple value and is it possible to let each value do a line break?

  • A checkbox field stores an array and get_field will always return an array. I don’t know anything about twig, but you’d need to loop over the array. You might want to check documentation for twig or ask this question where someone knows about it because I’ve never seen a twig question answered here, and there have been many.

  • thanks, I have resolved using

    <table class="field_table">
                    {% for field_name, field_value in fields if field_value is not empty %}
                       <td class="field_title"><strong>{{ field_name }}</strong></td>
    				   <td class="field_value">{{ field_value|join('\n')| nl2br }}</td>
                    {% endfor %}
Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.