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?

Donate and get more free time-saving code on this website in the future.