I new in Drupal 8 and I have an a problem, i want to change de look of my user_login_form, reading about that i knew that i could use the hook_form_alter for my purpose but I can't access the form variables in the template of Twig. My hook is the next:

function halcones2_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  switch ($form_id) {
    case 'user_login_form':
      //Altera el formulario para añadirle una plantilla y poder imprimirlo             
    $form['#theme'] = 'halcones2_user_login';        

To render the form to my template, that works but the form variables doesn´t appear like {{ form.name }} or {{ form.pass }} only I a can see de divs that i have in my template of twig. My source to do that is the link https://nireneko.com/articulo/2018/05/personalizar-formulario-plantilla-drupal-8 but my problem is the form variables. Someone can help me please??

  • Where is hook_theme implementation ? – berramou Sep 6 '19 at 21:47
  • Hi, well firstly like the link said (or I try to understand) it´s not necessary to implement de hook_theme if I use my template halcones2_user_login.html.twig to see the form, I try to use the halcones2_theme too but I don't know why when I use the 2 hooks in my halcones2.theme I receive an error but if I only put 1 hook in that file (halcones2.theme) I don't have any error but I don't see the variables form. My file .theme is in a sub-theme that I´ve created and it´s located in the root of my sub theme folder. My twig uses the route halcones2/templates/halcones2_user_login.html.twig . – Isaias B Sep 7 '19 at 22:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.