0

I have a module to create and handle surveys. I made a theme originally for it called "survey" and everything worked fine. I am now trying to rename the theme/template to "questionList", but am getting "Theme hook questionList not found" in the logs.

My working code with the theme name "survey" is shown below.

survey.module

 /**
 * Implements hook_theme().
 */
function survey_theme($existing, $type, $theme, $path)
{
    $variables = array(
        'survey' => array(
            'variables' => array(
                'questions'    => NULL,
            ),
        ),
    );
    return $variables;
}

RadioQuestionController.php

    public function getAllQuestions()
    {
        $element['#questions'] = array(1,2,3,4,5);

        $element['#title'] = 'Radio Questions';
        $element['#theme'] = 'survey';
        return $element;
    }

survey.html.twig

{#
/**
 * @file
 * Default theme implementation to print list of questions.
 *
 * Available variables:
 *   - questions
 *
 * @ingroup themeable
 */
#}
<h1>Test</h1>

The above works fine and prints "Test" to the specified path in my .routing.yml file. However the following does not work.

survey.module

 /**
 * Implements hook_theme().
 */
function questionList_theme($existing, $type, $theme, $path)
{
    $variables = array(
        'questionList' => array(
            'variables' => array(
                'questions'    => NULL,
            ),
        ),
    );
    return $variables;
}

RadioQuestionController.php

    public function getAllQuestions()
    {
        $element['#questions'] = array(1,2,3,4,5);

        $element['#title'] = 'Radio Questions';
        $element['#theme'] = 'questionList';
        return $element;
    }

questionList.html.twig

{#
/**
 * @file
 * Default theme implementation to print list of questions.
 *
 * Available variables:
 *   - questions
 *
 * @ingroup themeable
 */
#}
<h1>Test</h1>

Is there something that I am missing that I need to change other than what is changed in the above code? Or is there something else going on?

2
  • 1
    Try to clear cache or disable and then re enable the theme again. Clearing a cache is required most of the times if you make a change to a theme or module in Drupal.
    – rashidkhan
    Sep 29, 2015 at 15:44
  • 1
    Lowercase the "L".
    – user21641
    Sep 29, 2015 at 17:42

1 Answer 1

1
function questionList_theme(...)

must have the name of the module, like :

function survey_theme($existing, $type, $theme, $path)
{
    $variables = array(
        'questionList' => array(
            'variables' => array(
                'questions'    => NULL,
            ),
        ),
    );
    return $variables;
}

will work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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