<p>You should be able to get your content by using a <code>for</code> loop on your Matrix field:</p>
<pre><code>{% for blocks in kHandle.yourMatrixfieldHandle.all() %}
    {{ block.fieldHandle }}
{% endfor %}
</code></pre>
<p>Alternatively, if you only have one block in there, you could use:</p>
<pre><code>{{ kHandle.yourMatrixfieldHandle.first().fieldHandle }}
</code></pre>

CC BY-SA 4.0
2021-01-04T14:56:46.340Z
2021-01-04T14:56:46.340Z
Oli
<p>CMS: <strong>Craft CMS 2</strong></p>
<p>In my admin panel I have globals set called <code>X (under &quot;Globals&quot; from the sidebar and defined in </code>craft_globalsets<code> in the db from Global-&gt;Settings-&gt;New global set)</code>.</p>
<p>A field for the field layout for the global set is defined by using as Content a Field type <code>Y</code> of <strong>Matrix type</strong> with several plain texts fields A,B,C,...</p>
<p><strong>How do I check/show such fields' values (A, B, C, ...) in twig?</strong></p>
<p>What I have tried: I see that in the other parts of the code the handle defined in <code>craft_globalsets</code> (or equivalently in Settings-&gt;Globals) is used to fetch the globals' field value</p>
<p>e.g. for Globals -&gt; set 'K' (handle in <code>craft_globalsets</code>: kHandle) there are several plaintext inputs and such are accessed in twig as:</p>
<blockquote>
<p>{{ kHandle.firstField}}</p>
</blockquote>
<p>and in fact it works - but when I od the same with set X</p>
<blockquote>
<p>{{xHandle.firstFiledInTheMatrix}}</p>
</blockquote>
<p>it's <code>null</code></p>
<p>I have also tried to do</p>
<blockquote>
<p>{%  set matrixFields = craft.fields.getFieldByHandle('Y') %}
{{  matrixFields }}</p>
</blockquote>
<p>but this returned only the field name.</p>
<p>Perhaps I should do something like {{ xHandle.firstFiledInTheMatrix.getMatrixContent | getFieldContent }} and a <strong>for loop</strong> on this? (currently guessing the function names here)</p>

<templating><matrix>
How to get values into twig template for fields of type Matrix in Craft CMS 2?
# How to get values into twig template for fields of type Matrix in Craft CMS 2?

(Asked by: username_0 on 2021-01-04)

CMS: **Craft CMS 2**

In my admin panel I have globals set called `X (under "Globals" from the sidebar and defined in` craft\_globalsets `in the db from Global->Settings->New global set)`.

A field for the field layout for the global set is defined by using as Content a Field type `Y` of **Matrix type** with several plain texts fields A,B,C,...

**How do I check/show such fields' values (A, B, C, ...) in twig?**

What I have tried: I see that in the other parts of the code the handle defined in `craft_globalsets` (or equivalently in Settings->Globals) is used to fetch the globals' field value

e.g. for Globals -> set 'K' (handle in `craft_globalsets`: kHandle) there are several plaintext inputs and such are accessed in twig as:

> {{ kHandle.firstField}}

and in fact it works - but when I od the same with set X

> {{xHandle.firstFiledInTheMatrix}}

it's `null`

I have also tried to do

> {% set matrixFields = craft.fields.getFieldByHandle('Y') %}
> {{ matrixFields }}

but this returned only the field name.

Perhaps I should do something like {{ xHandle.firstFiledInTheMatrix.getMatrixContent | getFieldContent }} and a **for loop** on this? (currently guessing the function names here)

**Tags:** templating, matrix


---

## 1 answers

### Answer by username_1 on 2021-01-04. Score: 2 | Accepted answer

You should be able to get your content by using a for loop on your Matrix field:
{% for blocks in kHandle.yourMatrixfieldHandle.all() %}
    {{ block.fieldHandle }}
{% endfor %}

Alternatively, if you only have one block in there, you could use:
{{ kHandle.yourMatrixfieldHandle.first().fieldHandle }}


---

