0

Currently I have the following code in my module file:

function mymodule_theme_suggestions_credit_report(array $variables) {
  return [
    'pdf_report__' . $variables['elements']['#view_mode']
  ];
}

function mymodule_theme($existing, $type, $theme, $path) {
  return [
    'pdf_report' => [
      'render element' => 'elements'
    ]
  ];
}

And I have inside /mymodule/templates/ 2 twig files

  1. pdf-report.html.twig (just added the code from entity-html.twig)
  2. pdf-report--new-style.html.twig

And I have a view mode in my pdf-report called new_style.

I've read documentation and it looks like this should work, but it doesn't.

I tried doing the following:

function mymodule_theme_suggestions_credit_report(array $variables) {
  return [
    'pdf_report__' . $variables['elements']['#view_mode']
  ];
}

function mymodule_theme($existing, $type, $theme, $path) {
  return [
    'pdf_report' => [
      'render element' => 'elements',
      'template'  => 'pdf-report--orcutt-style',
      'base hook' => 'pdf_report',
    ]
  ];
}

But this replaces all of the view modes, not just the one I want.

1 Answer 1

1

Now the new theme hook is the same as the base hook. You need to declare the more specific theme suggestion as hook:

function mymodule_theme($existing, $type, $theme, $path) {
  return [
    'pdf_report__new_style' => [
      'base hook' => 'pdf_report',
    ],
  ];
}
1
  • It worked!, I can't believe I didn't tried this before, thank you!
    – Kahlet
    Commented Sep 8, 2020 at 0:49

Your Answer

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

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