0

I have a homepage node-type in which I have an entity-reference field holding 3 references to 3 separate custom blocks.

The theme I'm working on requires that my 3 element reference field needs to be output in page.html.twig. I have overridden page.html.twig and I can see changes I have introduced once my caches are cleared.

My research led me to implementing a custom module to preprocess my homepage ouput and include the data I want printed from page--front.html.twig, code below:

function mymodule_preprocess_page(&$variables, $hook) {
    // $url_obj = Url::fromRoute('<front>');
    die('tested');
    dsm($variables);
    drupal_set_message('testing');
}

My problem is my preprocess function is not triggered. The module is enabled, and calling die() outside a function does "kill" the site, so the module file is recognized.

I would appreciate any help.

0

Module names are all lowercase or underscore. Your preprocess function name must start exactly with the same name as your module/theme. Never uppercase.

function mymodule_preprocess_page(&$variables) {
  ...
}

And there is no $hook parameter in this case, the _page function name suffix already declares this function as a specific hook only for the page hook type.

| improve this answer | |
  • Sorry, that was a typo. I also removed the extra argument. They are both corrected but did not solve my problem. – sisko Jun 3 at 8:48
  • Also remember that preprocesses are cached. Everytime you change the preprocess function, you must wipe the cache. Once the page was successfully rendered, it will be cached again, and you must wipe the cache again to see changes. – Hudri Jun 3 at 8:57
  • Yes, I have been flushing the caches with each update – sisko Jun 3 at 12:17

Your Answer

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

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