I'm using drupal 6, I wanted to give feed back on a simple quiz (that is answered during user registration - to be a profile field). I made a template for the profile page: user-profile.tpl.php

And the code (at the bottom of the page) works fine, but it doesn't work when I try the same code in the template(for the specific block I want): block-block-10.tpl.php

I added this function to template.php, to (TRY) make $account avaialble to block-10

function blockaccess() {
// access globals  
global $account;
global $node; 

What do I need to change?

the code in block-block-10.tpl.php:

<div class="block-content-inner">
  $correct_ans = "3) I'm from Spain.";
  $quiz_ans = $account->profile_quizoffer_ans;
  print $quiz_ans;
  print "--------------------------------------------</br>";
  print '<h3>チラシの裏のクイズ:</h3><table><tr><th border="1">Q: Where are you from?</th><th>Result</th></tr>'; 
  if ($quiz_ans == $correct_ans) {
    print '<tr><td width="200"><p style="color:green">';
    print $quiz_ans; 
    print '</p></td><td><strong><p style="background-color:green"><font color="white">CORRECT</font></strong></p></td></tr><tr><td>You passed the quiz!</td></tr>';

  else {
    print '<tr><td width="200"><p style="color:red">';
    print $account->profile_quizoffer_ans; 
    print '</td><td><strong><p style="background-color:red"><font color="white">INCORRECT</font></strong></p></td></tr><tr><td>You didn'."'".'t pass the quiz!</td></tr><tr><td>The correct answer was:</td><td>';
    print $correct_ans;
    print "</td></tr>"  ;

  print "</table>"; ?>

Try global $user; rather than global $account;.

  • cheers Scott! The global $user does work (i can dsm($user) now), but the key variable I need is: $quiz_ans = $account->profile_quizoffer_ans; I dont understand how I can make global $user but global $account doesnt work – LJ xhanswers Sep 22 '13 at 23:41

I added $account = user_uid_optional_load(); to block-block-10.tpl.php and its working fine!

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