<p>If you only need your custom fields, you can could use <code>craft.app.fields.getLayoutTabsById()</code> to grab the relevant tabs then do something like:</p>
<pre class="lang-twig prettyprint-override"><code>{% set section = craft.app.sections.getSectionByHandle('handle') %}
{% set fieldLayoutId = section.getEntryTypes[0].getFieldLayout().id %}
{% set fieldLayoutTabs = craft.app.fields.getLayoutTabsById(fieldLayoutId) %}

{% for tab in fieldLayoutTabs %}
    {% for field in tab.elements %}
        {% if field is instance of(&quot;craft\\fieldlayoutelements\\CustomField&quot;) %}
            &lt;pre&gt;{{ field.field.handle }} - {{ field.width }}&lt;/pre&gt;
        {% endif %}
    {% endfor %}
{% endfor %}
</code></pre>
<p><code>field is instance of(&quot;craft\\fieldlayoutelements\\CustomField&quot;)</code> will element filter attributes (title, dates...) out.</p>

CC BY-SA 4.0
2021-09-10T07:54:31.193Z
2021-09-10T07:54:31.193Z
Oli
<p>I'm trying to show all my Channel's fields on front end, as they are shown on the CP:</p>
<pre><code>{% set section = craft.app.sections.getSectionByHandle('handle') %}
{% set fieldLayout = section.getEntryTypes[0].getFieldLayout() %}

{% for field in fieldLayout.getFields() %}
    {# {{ field }} #}
{% endfor %}
</code></pre>
<p>How can I get the fields widths as they are shown in the CP?</p>
<p>As seen in the <code>fieldlayouttabs</code> table &gt; <code>elements</code> &gt; <code>width</code> value.</p>

<templating><field><layout>
How to get field widths when using getFieldLayout()?
# How to get field widths when using getFieldLayout()?

(Asked by: username_0 on 2021-09-09)

I'm trying to show all my Channel's fields on front end, as they are shown on the CP:
{% set section = craft.app.sections.getSectionByHandle('handle') %}
{% set fieldLayout = section.getEntryTypes[0].getFieldLayout() %}

{% for field in fieldLayout.getFields() %}
    {# {{ field }} #}
{% endfor %}

How can I get the fields widths as they are shown in the CP?
As seen in the fieldlayouttabs table > elements > width value.

**Tags:** templating, field, layout

---

## 1 answers

### Answer by username_1 on 2021-09-10. Score: 0 | Accepted answer

If you only need your custom fields, you can could use craft.app.fields.getLayoutTabsById() to grab the relevant tabs then do something like:
{% set section = craft.app.sections.getSectionByHandle('handle') %}
{% set fieldLayoutId = section.getEntryTypes[0].getFieldLayout().id %}
{% set fieldLayoutTabs = craft.app.fields.getLayoutTabsById(fieldLayoutId) %}

{% for tab in fieldLayoutTabs %}
    {% for field in tab.elements %}
        {% if field is instance of("craft\\fieldlayoutelements\\CustomField") %}
            {{ field.field.handle }} - {{ field.width }}
        {% endif %}
    {% endfor %}
{% endfor %}

field is instance of("craft\\fieldlayoutelements\\CustomField") will element filter attributes (title, dates...) out.


---

