For a url like domain.com/example/123 where 123 is a Matrix Block ID (not an Entry ID), can I get the associated entry for given block ID in a template?

Or, for a more general approach, what would be the best way to get that Matrix Block element and its Entry element when you only have a block ID?

Edit: so ideally:

{% set block = craft.matrixBlocks.id(craft.request.segment(2)).first() %}
{% set entry = block.getOwner() %}

...which isn't possible now.

  • Is 123 the block ID or the block index?
    – jpea
    Commented Jul 9, 2014 at 13:45
  • The ID. Not the index.
    – Low
    Commented Jul 9, 2014 at 13:46
  • Gotcha - I posted something that might work below. I haven't tested it, but it's the gist of something that should work.
    – jpea
    Commented Jul 9, 2014 at 13:49

2 Answers 2


At the time of this writing, the ideal solution isn't possible. But, as jpea suggested, creating a plugin was dead easy, so here it is:

Low Blocks

...which lets me use syntax like this:

{% set block = craft.lowBlocks.id(craft.request.segment(2)) %}
{% set entry = block.owner %}
  • Now that's the way to answer your own question, 4 hours later with the plugin you just wrote to solve it. ;) Commented Jul 9, 2014 at 18:00
  • Heck yeah - nice work!
    – jpea
    Commented Jul 9, 2014 at 18:53
  • Someday I'm going to answer my own question with my own plugin. Nicely done.
    – Matt Stein
    Commented Jul 9, 2014 at 21:06

Perhaps just grab the URL segment and set it as a variable:

{% set mID = craft.request.getSegment(2) %}
{% for entry in craft.entries.section('whatever') %}
   {% for block in entry.myMatrixField.id(mID) %}
     {{ block.someNestedFieldInsideOfMyMatrixField }}
   {% endfor %}
{% endfor %}
  • Yeah, I was hoping to avoid looping through every entry...
    – Low
    Commented Jul 9, 2014 at 13:49
  • 2
    Actually, if I remember correctly one of the discussions I had with Brandon, this wouldn't be too taxing in terms of queries. Craft is smart enough to only fetch what it needs (the entry_id in this case) Commented Jul 9, 2014 at 13:51
  • Even with Yii's ORM, it still grabs the entries before it can grab the Matrix block. Ideally, yes, it would be great if there's an interface somehow directly into Matrix ID's. It wouldn't be a tough plugin to write though if there's no native way to do it.
    – jpea
    Commented Jul 9, 2014 at 15:16

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.