1

I need to define custom html.html.twig file for particular url. What I did is given below:

/**
 * Implements hook_theme().
 */
function mymodule_theme() {
  return array(
    'html__ajax' => array(
      'render element' => 'elements',
    ),
  );
}
/**
 * Implements hook_theme_suggestions_HOOK().
 */
function mymodule_theme_suggestions_html(array $variables) {
  $template_suggestions = array();
  // This is used to display only ajax $content.
  if (isset($_GET['ajax']) && $_GET['ajax'] == 1) {
    $template_suggestions[] = 'html__ajax';
  }
  return $template_suggestions;
}

I have copy pasted html.html.twig file from my theme and put it inside my module's template folder and renamed it as html--ajax.html.twig. Changes are reflecting fine but not all default variables are not available in my custom html.html.twig file.

When I open the page I can see the content till Skip to main content link. Please help me what I am missing while declaring custom template file.

0

1 Answer 1

3

If you want to return 'render element' this would be 'html':

'render element' => 'html',

But you probably don't need this, better return the base hook so that drupal fetches the variables from the hook html:

function mymodule_theme() {
  return array(
    'html__ajax' => array(
      'base hook' => 'html',
    ),
  );
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.