1

I have one custom function in .module file. Need to call that function .template file. Below is my code snnipet:

function non_login_preprocess_page(&$vars) { if(module_exists('test') && function_exists('test_get_rnd_data')){ $vars['rnd_data'] = test_get_rnd_data(); print_r("callled"); exit; } } 

the function exists does not return true. Is anything thing missing?

2
  • function_exists is a basic PHP method - if the file containing the function is included, which in the Drupal world equates to the module being enabled, there's no logical reason your code wouldn't work. Commented Oct 3, 2018 at 7:15
  • ohh got the issue. The issue was with the custom module. I had the backup of my custom module inside module folder with the different name. Due to which it was giving the false result. After deleting and clearing cache it works out. Commented Oct 3, 2018 at 9:20

1 Answer 1

1

Please try bellow code and use module_load_include() function.

function non_login_preprocess_page(&$vars) { module_load_include('module', 'module', 'test'); // **add this line** if(module_exists('test') && function_exists('test_get_rnd_data')){ $vars['rnd_data'] = test_get_rnd_data(); print_r("callled"); exit; } } 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.