<blockquote>
  <p>If I understand correctly, the $context variable passed to my hook should be a reference to that summary object.</p>
</blockquote>

<p>Nope... <code>$context</code> is a reference to the entire Twig rendering context of which your <code>bookings</code> objects will be a part of.</p>

<p>You can use xDebug or <code>var_dump</code> to see where your <code>bookings</code> objects are stored and loop though them as necessary from PHP.</p>

CC BY-SA 3.0
2015-05-13T21:55:28.403Z
2015-05-13T21:55:28.403Z
Brad Bell
<p>According to <a href="http://buildwithcraft.com/classreference/services/TemplatesService#hook-detail" rel="nofollow">the docs</a>, if I call a hook from within my template:</p>

<blockquote>
  <p>The $context argument will be the current Twig context array, which you’re free to manipulate.</p>
</blockquote>

<p>So I have a loop in my template where summary is a model I've created:</p>

<pre><code>{% for summary in bookings %}
    {% hook 'microsGetBooking' %}
{% endfor %}
</code></pre>

<p>If I understand correctly, the $context variable passed to my hook should be a reference to that summary object. However it always appears to be an EntryModel (in this case the template I'm calling this on has a URL that matches an entry in the CMS).</p>

<p>What am I missing here?</p>

<plugin-development><templating><hook>
Hook calls within a loop always get the Entry, not the loop context?
# Hook calls within a loop always get the Entry, not the loop context?

(Asked by: username_0 on 2015-05-13)

According to the docs, if I call a hook from within my template:

The $context argument will be the current Twig context array, which you’re free to manipulate.

So I have a loop in my template where summary is a model I've created:
{% for summary in bookings %}
    {% hook 'microsGetBooking' %}
{% endfor %}

If I understand correctly, the $context variable passed to my hook should be a reference to that summary object. However it always appears to be an EntryModel (in this case the template I'm calling this on has a URL that matches an entry in the CMS).
What am I missing here?

**Tags:** plugin-development, templating, hook

---

## 1 answers

### Answer by username_1 on 2015-05-13. Score: 1

> If I understand correctly, the $context variable passed to my hook should be a reference to that summary object.

Nope... `$context` is a reference to the entire Twig rendering context of which your `bookings` objects will be a part of.

You can use xDebug or `var_dump` to see where your `bookings` objects are stored and loop though them as necessary from PHP.


---

