Answers.Body: <p>Perhaps just grab the URL segment and set it as a variable:</p>
  
  <pre><code>{% set mID = craft.request.getSegment(2) %}
  {% for entry in craft.entries.section('whatever') %}
     {% for block in entry.myMatrixField.id(mID) %}
       {{ block.someNestedFieldInsideOfMyMatrixField }}
     {% endfor %}
  {% endfor %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-09T13:49:41.513Z
Answers.Text: Yeah, I was hoping to avoid looping through every entry...
Answers.UserDisplayName: Low
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-09T13:51:18.827Z
Answers.Text: 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)
Answers.UserDisplayName: Jérôme Coupé
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-09T15:16:37.523Z
Answers.Text: 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.
Answers.UserDisplayName: jpea
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-09T13:48:32.443Z
Answers.LastActivityDate: 2014-07-09T13:48:32.443Z
Answers.UserDisplayName: jpea
Answers.Body: <p>At the time of this writing, the ideal solution isn't possible. But, as <a href="https://craftcms.stackexchange.com/questions/856/can-i-get-an-entry-by-matrix-block-id/866#comment1366_857">jpea suggested</a>, creating a plugin was dead easy, so here it is:</p>
  
  <p><a href="https://github.com/low/lowblocks" rel="nofollow noreferrer"><strong>Low Blocks</strong></a></p>
  
  <p>...which lets me use syntax like this:</p>
  
  <pre><code>{% set block = craft.lowBlocks.id(craft.request.segment(2)) %}
  {% set entry = block.owner %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-09T18:00:00.490Z
Answers.Text: Now that's the way to answer your own question, 4 hours later with the plugin you just wrote to solve it. ;)
Answers.UserDisplayName: Simon Kuran
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-09T18:53:24.480Z
Answers.Text: Heck yeah - nice work!
Answers.UserDisplayName: jpea
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-09T21:06:50.703Z
Answers.Text: Someday I'm going to answer my own question with my own plugin. Nicely done.
Answers.UserDisplayName: Matt Stein
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-09T17:44:26.193Z
Answers.LastActivityDate: 2014-07-09T17:44:26.193Z
Answers.LastEditDate: 2017-04-13T12:51:00.200Z
Answers.UserDisplayName: Low
Body: <p>For a url like <code>domain.com/example/123</code> where <code>123</code> is a Matrix Block ID (not an Entry ID), can I get the associated entry for given block ID in a template?</p>
  
  <p>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?</p>
  
  <p><strong>Edit:</strong> so ideally:</p>
  
  <pre><code>{% set block = craft.matrixBlocks.id(craft.request.segment(2)).first() %}
  {% set entry = block.getOwner() %}
  </code></pre>
  
  <p>...which isn't possible now.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-07-09T13:45:04.907Z
Comments.Text: Is 123 the block ID or the block index?
Comments.UserDisplayName: jpea
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-07-09T13:46:31.250Z
Comments.Text: The ID. _Not_ the index.
Comments.UserDisplayName: Low
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-07-09T13:49:04.690Z
Comments.Text: Gotcha - I posted something that might work below. I haven't tested it, but it's the gist of something that should work.
Comments.UserDisplayName: jpea
Tags: <entries><matrix>
Title: Can I get an entry by Matrix Block ID?
ThreadText: # Can I get an entry by Matrix Block ID?
  
  (Asked by: username_0 on 2014-07-09)
  
  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.
  
  **Tags:** entries, matrix
  
  > **Comments:**
  > **username_1**: Is 123 the block ID or the block index?  
  > **username_0**: The ID. _Not_ the index.  
  > **username_1**: Gotcha - I posted something that might work below. I haven't tested it, but it's the gist of something that should work.  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_0 on 2014-07-09. Score: 11 | Accepted answer
  
  At the time of this writing, the ideal solution isn't possible. But, as [username_1 suggested](https://craftcms.stackexchange.com/questions/856/can-i-get-an-entry-by-matrix-block-id/866#comment1366_857), creating a plugin was dead easy, so here it is:
  
  [**Low Blocks**](https://github.com/low/lowblocks)
  
  ...which lets me use syntax like this:
  
  ```
  {% set block = craft.lowBlocks.id(craft.request.segment(2)) %}
  {% set entry = block.owner %}
  
  ```
  
  > **Comments:**
  > **username_3**: Now that's the way to answer your own question, 4 hours later with the plugin you just wrote to solve it. ;)  
  > **username_1**: Heck yeah - nice work!  
  > **username_4**: Someday I'm going to answer my own question with my own plugin. Nicely done.  
  
  ---
  
  ### Answer by username_1 on 2014-07-09. Score: 4
  
  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 %}
  
  ```
  
  > **Comments:**
  > **username_0**: Yeah, I was hoping to avoid looping through every entry...  
  > **username_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)  
  > **username_1**: 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.  
  
  ---
  
  