<p>This bothered me too until I switched to PHPStorm and started using this: <a href="https://github.com/nystudio107/craft-autocomplete" rel="nofollow noreferrer">https://github.com/nystudio107/craft-autocomplete</a>.</p>
<p>If that's not an option and you fancy extending Twig, you can use php's <code>get_class_methods</code> function to return the methods of a passed-in object.</p>
<p>Ultimately though, given the deep inheritance tree from Yii's base objects, listing out 100s of methods that you'll mostly never touch is not all that helpful, I find. When you need to do something complicated, you're best off digging through the Class Reference - at least you'll get descriptions of what the methods do, and their parameters.</p>
<p>(Related, I often use the <code>|keys</code> filter to dump out an object's properties.)</p>

CC BY-SA 4.0
2022-02-28T10:05:35.410Z
I'm not sure how to extend twig like that. I just might take the plunge and switch to phpstorm, even though I love how my VScode is set up now.
InanisAtheos
CC BY-SA 4.0
2022-02-28T10:45:19.177Z
If you wanted to explore extending Twig, just head to https://pluginfactory.io and tick the box for Twig Extensions - it'll generate all the plugin scaffolding for you to create your own Twig filters or functions. Then inside your function/filter you'd `return get_class_methods($object);` and that's about it!
James Smith
CC BY-SA 4.0
2022-02-21T10:10:58.373Z
2022-02-21T15:14:12.757Z
2022-02-21T15:14:12.757Z
James Smith
<p>This feels like it falls under silly/obvious questions, but I can't seem to find a decent answer anywhere, so I'm asking here:</p>
<p>How do I find out which methods for example, is available on an object? For example, I'm able to do <code>{{ entry.authors.one() }}</code> and get the first one in the object. Great, but if I didn't kow that <code>one()</code> existed, how would I find out? Now, in regular ol' PHP I'd <code>var_dump($authors)</code> or whatever, and whatever the object contained would be displayed, including methods. Doing the same in a twig template by either using <code>{{ dump(entry.authors() }}</code> or <code>{{ dd(entry.authors() }}</code> shows the object (I think?) but not the methods I'm able to use on it. In fact, it seems impossible to just look up what specific methods I'm able to use on a specific object. I'm sure that I'm just missing something though.</p>
<p>So how can I find out what I'm able to do with said object? Surely there must be a better way to know other than &quot;you'll have to guess&quot; or rely on abstract documentation which might not be relevant to a specific use case?</p>
<p>I realize the above example is incredibly simple, but obviously there are more complex situations that arise. Like when I'm digging down into multiple nested fields, looping through their children() etc, it's quite easy to get &quot;lost&quot;, as it were.</p>

<templating><yii><debugging>
Debugging with dump()/dd() within Twig templates
# Debugging with dump()/dd() within Twig templates

(Asked by: username_0 on 2022-02-17)

This feels like it falls under silly/obvious questions, but I can't seem to find a decent answer anywhere, so I'm asking here:

How do I find out which methods for example, is available on an object? For example, I'm able to do `{{ entry.authors.one() }}` and get the first one in the object. Great, but if I didn't kow that `one()` existed, how would I find out? Now, in regular ol' PHP I'd `var_dump($authors)` or whatever, and whatever the object contained would be displayed, including methods. Doing the same in a twig template by either using `{{ dump(entry.authors() }}` or `{{ dd(entry.authors() }}` shows the object (I think?) but not the methods I'm able to use on it. In fact, it seems impossible to just look up what specific methods I'm able to use on a specific object. I'm sure that I'm just missing something though.

So how can I find out what I'm able to do with said object? Surely there must be a better way to know other than "you'll have to guess" or rely on abstract documentation which might not be relevant to a specific use case?

I realize the above example is incredibly simple, but obviously there are more complex situations that arise. Like when I'm digging down into multiple nested fields, looping through their children() etc, it's quite easy to get "lost", as it were.

**Tags:** templating, yii, debugging

---

## 1 answers

### Answer by username_1 on 2022-02-21. Score: 4 | Accepted answer

This bothered me too until I switched to PHPStorm and started using this: <https://github.com/nystudio107/craft-autocomplete>.

If that's not an option and you fancy extending Twig, you can use php's `get_class_methods` function to return the methods of a passed-in object.

Ultimately though, given the deep inheritance tree from Yii's base objects, listing out 100s of methods that you'll mostly never touch is not all that helpful, I find. When you need to do something complicated, you're best off digging through the Class Reference - at least you'll get descriptions of what the methods do, and their parameters.

(Related, I often use the `|keys` filter to dump out an object's properties.)

> **Comments:**
> **username_0**: I'm not sure how to extend twig like that. I just might take the plunge and switch to phpstorm, even though I love how my VScode is set up now.  
> **username_1**: If you wanted to explore extending Twig, just head to https://pluginfactory.io and tick the box for Twig Extensions - it'll generate all the plugin scaffolding for you to create your own Twig filters or functions. Then inside your function/filter you'd `return get_class_methods($object);` and that's about it!  

---

