1

I am trying to add templates for the paragraph in the custom module. It invokes only the paragraph.html.twig.

In theme suggestion, paragraph--example-ch-hero-panel.html.twig is given. I am using the same templates. By default, The template will be taken for the paragraph here. But here its not working. I am not using hook_theme in .module for this. because I am not passing any values to the templates.

even try this also

function example_ch_hero_panel_theme() {
  return [
    'paragraph__example_ch_hero_panel' => [
      'render element' => 'element',
      'template' => 'paragraph--example-ch-hero-panel',
      'base hook' => 'paragraph',
    ],
  ];
}

added theme registry too

function example_ch_hero_panel_theme_registry_alter(&$theme_registry) {
  $theme_registry['page']['path'] = drupal_get_path('module', 'example_ch_hero_panel') . '/templates';
}

Please try again later.Twig\Error\LoaderError: Template "modules/custom/example_ch_hero_panel/templates/page.html.twig" is not defined. in Twig\Loader\ChainLoader->getCacheKey()

can anyone sort out this issue.

  • 1
    Why are you not using hook_theme_suggestions_HOOK_alter? api.drupal.org/api/drupal/… That's the correct way to add suggestions for a theme hook. – Alfred Armstrong Jun 21 '19 at 16:27
  • Even its not working @AlfredArmstrong. I tried. – user94141 Jun 21 '19 at 16:29
  • What theme suggestion are you trying to add exactly? For the paragraph type? For the paragraph in a certain panel? Is it about adding that from a custom module specifically? Or would it by OK to be added from your theme as well? – leymannx Jun 21 '19 at 23:13
  • @leymannx, paragraph--example-ch-hero-panel.html.twig for this suggestion. – user94141 Jun 22 '19 at 6:33
0

Your problem is coming from this code:

$theme_registry['page']['path'] = drupal_get_path('module', 'example_ch_hero_panel') . '/templates';

The first array key, page, means you are working the page template. You've told the system to look for page.html.twig in your module's /templates directory. It's not finding it, so you get that error.

Remove that hook altogether, it's not the right way to do what you are trying to do.

  • I removed this code. Only hook_theme function is calling. But still the base template is only calling not the overridden template. can you please help – user94141 Jun 22 '19 at 6:31

Your Answer

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