8 – How can I reference an entity field in a template file?

I am trying to theme the node add/edit form for a custom content type (for example, Album). I implemented hook_form_alter() in the theme.

function mytheme_form_alter(&$form, DrupalCoreFormFormStateInterface $form_state, $form_id) {
  switch ($form_id) {
    case "node_album_form":
      $form('#theme') = ('node_album_edit_form');
      break;
  }
}

That correctly intercepts the node add/edit form and passes it to my theme hook which also finds the correct template.

function mytheme_theme() {
  return (
    'node_album_form' => (
      'template' => 'node_album_edit_form',
      'path' => Drupal::theme()->getActiveTheme()->getPath() . '/scss/templates/album',
      'render element' => 'form'
    ),
  );
}

In node_album_edit_form.html.twig, I can confirm that changes there alter only the album add/edit form and that I can remove elements with {{ form|without('advanced', 'footer', 'actions') }}, for example.

What I cannot do is placing the form fields where I want them because I’m not using the right reference to the field.

<div class='myfancydiv album-title-field'>{{ field_album_title }}</div>
<div class='myfancydiv album-artist-field'>{{ field_artist }}</div>

I tried any of the following, but they didn’t work.

  • {{ field_album_title }}
  • {{ form.field_album_title }}
  • {{ album_title }}

How can I reference an entity field in a template file?