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.

1

1 Answer 1

1

You can create a custom HTML tag using the following code.

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

Another solution is custom theme function that creates the button. In this case, the theme function can be used by code similar to the following one.

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

You can read more about rendering custom templates on Create custom twig templates for custom module.

0

Your Answer

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

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