0

I'm adding a few links to a views twig template file and I would like to render them as a dropbutton. For example ...

enter image description here

Is this at all possible ... to render this in twig? If this were a form, I understand how I could define it, but it's just a straight collection of links. I'm sure I could locate some other CSS and JS to make this work, but would love for it to just keep the consistent look if possible.

Thanks!

1 Answer 1

0

You can build and manipulate render arrays inside a Twig template, and then render them with the render_var() function or the |render filter: https://www.drupal.org/node/2448219

As dropbutton is a render element this means you can define it in Twig just as you would in a form, and then directly render it.

1
  • Awesome! Thanks! I've used Twig with Symfony before but am a little new to D8 theming. Took me a minute to figure out it was best (only possible?) to create the render array in a preprocess function, but once I set a var to that array, Twig rendered it perfectly! Commented Jan 31, 2019 at 16:44

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.