I've created service which gets the raw data from custom content type. It looks like this :

    [front_page_slider] => Array
            [1] => Array
                    [title] => Lorem ipsum dolor sit amet
                    [body] =>Some example slider text up here
                    [field_image] => http://localhost/drupal8/sites/default/files/2016-05/slider1.png
                    [field_link_uri] => http://example.com
                    [field_link_title] => see more



After that i use array_push function to add this array $variables global variable.

I've tried to display any of this fields like this:

{{ dump(front_page_slider[1].title) }}

or this: {{ dump(front_page_slider) }}

But both return NULL. What I do wrong ?


Have you added 'front_page_slider to the variables array in your twig template definition?


function hook_theme(array $existing, $type, $theme, $path) {
  return [
    'template_name' => [
          'variables' => [
           'front_page_slider' => [],
  • Where should I create this .module file ? In the theme directory ? – El Danielo May 29 '16 at 11:33
  • Yes. Your main directory should contain a module_name.info.yml, module_name.module, and your template directory. – Kevin Nowaczyk May 30 '16 at 21:42

Install Devel Module (also enable devel kint sub module)and use kint

What is Kint?

Kint for PHP is a tool designed to present your debugging data in the absolutely best way possible.

In other words, it's var_dump() and debug_backtrace() on steroids. Easy to use, but powerful and customizable. An essential addition to your development toolbox.

This module allows to use kint($data) like as dpm()/dsm()/krumo() in Devel module.

something like
{{ kint(page) }}

Read more and some usage about kint.

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.