0

I'm a newbie to Drupal 8 and PHP coding in general so I hope my approach is not too much out of the lines. I'm trying to theme some parts of my website by fiddling a bit with templates, what I need to do is to get a value of a specific preprocess hook function and pass it to another one, to be more precise I need to print the page title of the currently visualized wizard page of my Webform into the Page Title block, so it would show both the form main title and the current page title, basically generate a twig variable to put inside my page-title.html.twig template.

to get that value I've been doing the following:

function MYTHEME_preprocess_webform(&$variables){
  //Gets the current wizard page id
  $current_page = $variables['element']['progress']['#current_page'];
  //gets its correspondig value
  $page_title = $variables['element']['elements'][$current_page]['#title'];
  $variables['page_title'] = $page_title;
}

But of course, the value {{ page_title }} would only be available inside the webform.html.twig template and not inside the page-title.html.twig template.

Is there a way to have those variables available inside the MYTHEME_preprocess_page_title hook instead? Or is there a better approach?

  • You can't pass variables in general, but you can pass the title by setting $form['#title']. Probably too late late in this hook, better try a form alter hook. – 4k4 Jun 13 at 19:27

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.