0

I'm working on a theme that using hook_preprocess_node and hook_preprocess_page and everything is working fine. However, whenever I go to any admin pages, it's throwing me some errors because the array changes. So what I'm trying to achieve is to add a condition only to run this preprocess function if using my theme.

How can I limit the preprocess function base on my theme?

2

You can check theme active with function:

<?php

$active = \Drupal::theme()->getActiveTheme()->getName();

Get list all themes with:

<?php

$themes = \Drupal::service('theme_handler')->listInfo()
|improve this answer|||||
0

If you implement the preprocess functions in your theme's template.php file, those will only be executed on the pages where the theme is applied.
So, if your admin theme is different (which is the case almost every time), the preprocess functions from your site theme would not be executed.

|improve this answer|||||
  • I'm on D8 so I'm not using template.php instead I'm using .theme. Which I do not think that it matters. My admin theme is different and the process function are still been execute. =(. I will add more information about the errors that I'm getting. – itsdarrylnorris Jan 22 '16 at 4:18
  • Oops.. Didn't see the 8 tag on the question. The preprocess functions are technically specific to the theme. Not sure why are they executing on a different theme. It will be good if you could add the code which you are trying out. – AjitS Jan 22 '16 at 4:23
  • 2
    mytheme.theme and mymodule.module files are run on every page load, when the corresponding theme/module is activated. – 4k4 Jan 22 '16 at 7:27

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.