1

I'am building a website (craftcms 3.4+) where I'll need frontend entry editing. Therefore I'll need the fieldlayout of an entry. This is what I'll have:

{% for tab in entry.fieldLayout.tabs %}
        <div class="form__row">
            <h3>{{ tab.name }}</h3>
        </div>
        {% for field in tab.getFields() %}
            <div class="form__row">
                {% if field.type == 'plainText' %}
                    <label for="etg">{{ field.name }}</label>
                    <input type="text" name="fields[{{ field.handle }}]" value="{{ attribute(entry, field.handle)}}">
                {% endif %}
            </div>
        {% endfor %}
{% endfor %}

The problem of this is that field.type not excist. I'll need that because of the different field types I'm using. How I'll get the th

1 Answer 1

2

You can use the instance of test (docs)

{% if field is instance of ('craft\\fields\\PlainText') %}

or use className (docs).

{% if field.className == 'craft\\fields\\PlainText' %}

In full:

{% for tab in entry.fieldLayout.tabs %}
    <div class="form__row">
        <h3>{{ tab.name }}</h3>
    </div>
    {% for field in tab.getFields() %}
        <div class="form__row">
            {% if field is instance of ('craft\\fields\\PlainText') %}
                <label for="etg">{{ field.name }}</label>
                <input type="text" name="fields[{{ field.handle }}]" value="{{ attribute(entry, field.handle)}}">
            {% endif %}
        </div>
    {% endfor %}
{% endfor %}

You can see all native Craft field types here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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