I activated the devel and devel kint modules. I also activated twig debugging, so, I can know which are templates used by Drupal.
So, I created a content-type named album that contains a field named tracks.
Now, I want customize this content type, so I created node--album.html.twig
in templates folder of bartik, which works so I can begin to customize this template.
Now, I have to know which are variables used by this template. In comment section of node--album.html.twig
I can read that content
variable can be used to display content of page. I also read I can use subset of content, such as content.field_example to display a field.
OK, so if I want to modify rendering of field_tracks I can use content.field_tracks
. Before using this variable I wanted to know all content variable, so I've written [[ kint(content) ]]
in content section of this file. I rebuilt the cache, and I seen that content is an array, not an object as suggested in comment section of node file.
So, if I print [[ content.field_tracks ]]
it returns nothing.
If I use kinkt()
without parameters it breaks drupal and point me to core/install.php.
The same as I use d()
without parameters.
At this point I am confused: there is a way to modify node--type twig templates without creating a file for each field?
[[ ]]
is not valid twig syntax, you need to use curly brackets{{ content.field_tracks }}
. Make sure you flush the cache to see changes. Alternatively, this should also work{{ node.field_tracks.value }}