Add a html field to a form in drupal 8 & 9

The Form API changed a bit over the years. This is the way add a html field to a form in drupal 8 & 9.

$form['price'] = [
   '#markup' => '<h2>' . $node->get('field_price')->getString() . '$</h2>',
];

 

 

Saved you some valuable time?

Buy me a drink 🍺 to keep me motivated to create free content like this!