I am trying to find the variable name for the content link in a view.

{{ kint(content) }} makes the page crash, probably because the variable is too big.

The same is true for the following code.

function my_theme_preprocess_field(&$variables, $hook) {

How can I find out what I am looking for?


Usually D8 $variables contain way too much data, and browser struggle to render it for you. I strongly suggest to use xdebug or similar debugger, all modern IDEs support it. It makes developer's life much easier. However, there is a workaround without having xdebug configured:

function my_theme_preprocess_field(&$variables, $hook) {
    // or better:
    // or:

This will return you top-level keys, then you can drill down to the next level:


For objects use type casting:

dpm((array) array_keys($object));

Set Kint as Variables Dumper on /admin/config/development/devel (with Devel Kint module enabled) and you'll get nicely structured output.

In Twig templates you can use something like this:

{% for key, value in content %}
    {{ key }}
{% endfor %}

UPD: Valuable comment from Kevin for TWIG:

{{ kint(content|keys) }}
| improve this answer | |
  • 1
    in twig template you can use {{ kint(content|keys }} – Kevin Mar 25 '18 at 21:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.