1

My human.tpl.php file is located in /tpl folder. Im trying to use hook_theme from the module:

    function human_theme($existing, $type, $theme, $path){
    return array(
        $item['human'] = array(
            'template' => 'human',
            'path' => drupal_get_path('module', 'human').'/tpl',
            'type' => 'theme',
            'variables' => array(),
        ),
    );
    return $item;
}

Why is this not working? I have some basic html code in my template file for testing purposes so it should show me something, but I get nothing back. If more information is needed, please let me know and I will add. Full code of a .module file can be found here.

  • remove type, its automatically derived from module/theme. Also you've not implemented template_preprocess_human() function which will define value of all your template file variables. Defining preprocess function might help. – Yogesh Oct 3 '16 at 12:43
1

You have two returns (the second will never be hit). You have declared your array twice. It should be this:

function human_theme($existing, $type, $theme, $path){
  return array(
    'human' => array(
      'template' => 'human',
      'path' => drupal_get_path('module', 'human').'/tpl',
      'type' => 'theme',
      'variables' => array(),
    ),
  );
}
|improve this answer|||||
  • Thank you, but it still doesn't show any of my template code which is just a simple div with "test" string – Viktor Oct 3 '16 at 12:21
  • Did you clear your cache? – Jaypan Oct 3 '16 at 12:39
0

In order for Drupal to find these new template files specified in hook_theme() you have to also clear the theme cache.

Also look into theme debugging for Drupal which will show you theme suggestions that show which template files are being used to generate sections of a page.

|improve this answer|||||
0

Thank you for all the answers, I used all of your suggestions, but the problem was with _page() function. After going through multiple examples I realized that I have to return $render_array, so now my human_page function looks like this:

function human_page(){
    //LOAD CUSTOM CONTENT TYPE FROM DB
    $result = entity_load('node', false, array('type' => 'human'));

    $render_array = array(
        '#theme' => 'human',
        '#items' => $result,
        '#title' =>t('ARGUMENT'),
    );
    return $render_array;
}

Lesson learned: Don't return simple variables in a page function because it will not work :)

|improve this answer|||||
  • Why wouldn't node be a variable passed in? You also are not passing a variables array to your function. – Kevin Oct 3 '16 at 13:19

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.