I´m using quiz module in Drupal 7, and need to theme the output in "My Results" (wich is a tab in the user profile page).

Here´s the module´s function :


 * Theme the user results page.
 * @param $results
 *  An array of quiz information.
 * @return
 *  Themed html.
 * @ingroup themeable
function theme_quiz_get_user_results($variables) {
  $results = $variables['results'];
  $rows = array();

  while (list($key, $result) = each($results)) {
    $interval = _quiz_format_duration($result['time_end'] - $result['time_start']);
    $passed = $result['score'] >= $result['pass_rate'];
    $grade = $passed ? t('Passed') : t('Failed');
    $passed_class = $passed ? 'quiz-passed' : 'quiz-failed';
    if (!is_numeric($result['score'])) {
      $score = t('In progress');
    elseif (!$result['is_evaluated']) {
      $score = t('Not evaluated');
    else {
      if (!empty($result['pass_rate']) && is_numeric($result['score'])) {
        $pre_score = '<span class = "' . $passed_class . '">';
        $post_score = ' %<br><em>' . $grade . '</em></span>';
      else {
        $post_score = ' %';
      $score = $pre_score . $result['score'] . $post_score;
    $rows[] = array(
      'title'       => l($result['title'], 'node/' . $result['nid']),
      'time_start'  => format_date($result['time_start'], 'short'),
      'time_end'    => ($result['time_end'] > 0) ? format_date($result['time_end'], 'short') . '<br />' . t('Duration :  @value', array('@value' => $interval)) : t('In Progress'),

      'score'       => $score,
      'evaluated'   => $result['is_evaluated'] ? t('Yes') : t('No'),
      'op'          => l(t('View answers'), 'user/quiz/' . $result['result_id'] . '/userresults'),


  if (empty($rows)) {
    return t('No @quiz results found.', array('@quiz' => QUIZ_NAME));

  $header = array(
    t('@quiz Title', array('@quiz' => QUIZ_NAME)),

  $output = theme('table', array('header' => $header, 'rows' => $rows));
  $output .= '<p><em>' . t('@quizzes that are not evaluated may have a different score and grade once evaluated.', array('@quizzes' => QUIZ_NAME)) . '</em></p>';
  return $output;

Now, all I need is to theme the output, and maybe add some special header before the results.

I´ve tried this at my template.tpl.php file, without any success:

function mythemename_quiz_get_user_results($variables) {
print "This is some information";
print "<div class="results">";
print $variables;
print "</div>";

Now I know that print $variables; isn´t the way it should print an array, but the way to do this in Drupal 6 was this (I´ve took this code from an issue in Drupal´s forums):

function phptemplate_quiz_get_user_results($results) {
  // $results - An array of quiz results.
  // overriding statements  

The function´s name changed, but the process shouldn´t be similar?

Thanks for your help!

  • template.tpl.php file ? If you mean template.php then this should work, you will have to clear the cache though.
    – 2pha
    Commented Feb 22, 2013 at 14:56
  • Yes, I´m sorry, I mean template.php. But after clearing the cache, it didn´t worked either... That´s why I thought that maybe the code to print the variables is wrorng.
    – Rosamunda
    Commented Feb 22, 2013 at 15:10
  • oh....so your function is being called? The variable sent to the function is an array, so your can't just print it. Maybe just copy and paste the original function and alter it to add what you need. If your function is not being called, double check the name of your function, I often get caught out by typos in function names.
    – 2pha
    Commented Feb 22, 2013 at 15:14
  • Thanks for your reply! The thing is that if I print "function mythemename_quiz_get_user_results($variables) { print_r($variables);" they do print (without any format, because of the print_r() statement), but if I try "print $variables;" they won´t.
    – Rosamunda
    Commented Feb 22, 2013 at 15:23
  • print is for printing strings, you will have to print each part of the array separately. The same way the original theme_quiz_get_user_results does.
    – 2pha
    Commented Feb 23, 2013 at 2:34

1 Answer 1


Copy and paste (and rename) the original theme function to your template.php file, than just change what you need. Remembering that $variables is an array. Use the dpm function of the devel module to look at what values are in $variables that you can use.

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.