0

Drupal 8 does not use HTML button tag for creating buttons, it instead uses the input tag to create buttons. This works fine for most part, except for buttons which include an icon gets messed up by themes which replace the icons with a gradient. For example, Bootstrap theme will replace the button icon with gradient, that makes the button empty.

Is there a way to create a button via render array that will generate <button ...><img ... style button?

Alternatively, is there a way for a module to only use a twig template in special case, but not all the time.

Other ideas?

Update: May 7 2020.


I have filed a Drupal Core issue to support new render type for imagebutton, hopefully it will get some attention, as this can't really be solved in contrib space.

0

You can create a custom HTML tag like this:

return [
  '#type' => 'html_tag',
  '#tag' => 'button',
  '#value' => 'whatever value...',
];

Another solution is to render a custom theme that creates the button, like:

return [
  '#theme' => 'your_template',
];

You can read more about rendering custom templates here.

| improve this answer | |
  • A theme independent solution is needed, so the above is not suitable. – amit Jan 8 at 21:49
  • You can do this in a custom module. Your_theme is just the name of the template name. Look at the link provided. You have to define the template in hook_theme in your module. – user72672 Jan 8 at 22:16
  • This is already in place, however when other themes are used they look awkward for buttons with icon created in our custom module. I am interested in a more capable solution, where our module does not have to dictate styling to the theme. – amit Jan 9 at 6:04
  • You can add styling and Libraries to modules too – user72672 Jan 9 at 7:00

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.