1

I'm trying to create a custom markup for a views-block. What I want to do is similar to what someone is trying to do here (How to create a custom markup for a views-block?).

My view-block has 3 items and I want to create a template where I can individually place them using HTML code. At the moment it just gets rendered from {{ content }} in my block--views-block--latest-block-1.html.twig. I guess I'd need to check how the three elements are stored in the content so that I can individually place them in my HTML markup.

The Twig dump function however doesn't seem to work. I get the following error message when loading my webpage:

PHP message: PHP Warning: Leaked 2 hashtable iterators in Unknown on line 0

What's going on?

1
  • The dump function never worked for me in last two years :D
    – user21641
    Commented Jan 27, 2016 at 8:41

2 Answers 2

3

Probably because there are some recursive data structures in there. Try installing kint from the devel project, I'm not sure right now if it replaces dump() or if it provides an alternative kint() but one of those should give you much better output.

2
  • Thanks. This worked. The content dump is huge and finding the info I need seems quite impractical. Maybe the way I was thinking of doing this isn't correct.
    – KristofDM
    Commented Jan 26, 2016 at 21:29
  • Node and essentially all entity templates have two primary variables to work with. content, that's the prepared render array according to your formatter configuration. You should hardly ever need anything except content, content.some_field and content.some_field.0 (nice way of getting just the inner part of a field formatter without standard field templates around it). The second is node. That's the node object, with the raw field values. E.g. node.body.value or node.some_field.target_id.
    – Berdir
    Commented Jan 27, 2016 at 0:39
0

It might be easier to add the html in another twig. Look for #type and #template keys in content. Each array with this keys inside will invoke other templates, which will then after they are processed invoke at least a another level of templates. You can see this, if you enable twig debugging and look in the html source in your browser:

Locating Template Files with Debugging

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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