<p>Each block within your Matrix field already has an ID, which you can access via <code>block.id</code> within a for-loop on your Matrix field:</p>

<pre><code>{% for block in entry.myMatrixField %}
    ID: {{ block.id }}
{% endfor %}
</code></pre>

<p>If you want to be able to query directly for a specific Matrix block, you can use the <a href="https://github.com/low/lowblocks" rel="nofollow">Low Blocks</a> plugin, which provides a <code>craft.lowBlocks.id()</code> function for accessing a block by its ID:</p>

<pre><code>{% block = craft.lowBlocks.id(123) %}
</code></pre>

CC BY-SA 3.0
2016-02-03T19:35:57.507Z
I believe the block.id is only available after the page is saved.
Lewis Jenkins
CC BY-SA 3.0
2016-02-16T21:46:54.953Z
After a bit of work on this, `block.id` isn't necessarily what I want. Particular when I'm outputting blocks from redactor, it would end up counting several paragraphs as a single block
kai
CC BY-SA 3.0
2016-02-03T14:11:25.053Z
2016-02-03T14:11:25.053Z
Brandon Kelly
<p><a href="http://medium.com/" rel="nofollow noreferrer">Medium</a> has a feature (that's likely the groundwork for their paragraph commenting, among other things) that adds an id to every tag inside of an article. Like so</p>

<p><a href="https://i.sstatic.net/vir64.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/vir64.jpg" alt="medium having an id on every paragraph"></a></p>

<p>I'm interested in replicating the behavior with Craft, in such a way that I can then write queries like <code>element = craft.entries.find(2).element.find(120)</code></p>

CC BY-SA 3.0
2016-02-03T06:00:52.853Z
I might answer this myself if I get time, but for the moment I'll leave it
kai
<templating><matrix>
IDing every descendent of a matrixfield
# IDing every descendent of a matrixfield

(Asked by: username_0 on 2016-02-03)

[Medium](http://medium.com/) has a feature (that's likely the groundwork for their paragraph commenting, among other things) that adds an id to every tag inside of an article. Like so

[![medium having an id on every paragraph](https://i.sstatic.net/vir64.jpg)](https://i.sstatic.net/vir64.jpg)

I'm interested in replicating the behavior with Craft, in such a way that I can then write queries like `element = craft.entries.find(2).element.find(120)`

**Tags:** templating, matrix

> **Comments:**
> **username_0**: I might answer this myself if I get time, but for the moment I'll leave it  

---

## 1 answers

### Answer by username_1 on 2016-02-03. Score: 2

Each block within your Matrix field already has an ID, which you can access via block.id within a for-loop on your Matrix field:
{% for block in entry.myMatrixField %}
    ID: {{ block.id }}
{% endfor %}

If you want to be able to query directly for a specific Matrix block, you can use the Low Blocks plugin, which provides a craft.lowBlocks.id() function for accessing a block by its ID:
{% block = craft.lowBlocks.id(123) %}

> **Comments:**
> **username_2**: I believe the block.id is only available after the page is saved.  
> **username_0**: After a bit of work on this, `block.id` isn't necessarily what I want. Particular when I'm outputting blocks from redactor, it would end up counting several paragraphs as a single block  

---

