views:

37

answers:

2

i have a template "views-view-field--tracker--name.tpl.php" for a view called tracker, and i am using an If...Else Statement in the template to print fields.

<?php
if ($node ->uid == 0) {
  print $view->field['field_authorname_value']->render($row);
} else {
  print $view->field['name']->render($row);
}
?>

The above code is not functioning as it should, its printing the first part nicely but not the second part. Though, printing without if statement seems to work ok. eg:

<?php
print $view->field['name']->render($row);
?>

Not sure whats wrong with the code, so looking for answers

A: 

I'm not sure exactly. What happens when you turn the if statement around?

<?php
if ($node ->uid != 0) {
  print $view->field['name']->render($row);
} else {
  print $view->field['field_authorname_value']->render($row);
}
?>

Or use a switch statement:

<?php
switch ($node ->uid) {
    case 0:
        print $view->field['field_authorname_value']->render($row);
        break;
    default:
        print $view->field['name']->render($row);
}
?>
jonfhancock
i am getting same result as earlier.
A: 

In drupal, an annoymous user == 0. However, you should probably check this first to ensure /what/ uid, your actually checking against. In other words, when you are debugging your page insert

echo "uid is: ".$node ->uid;

/before/ the if statement, and that will let you know what you are checking against (i.e if it is always 0 or something other than 0 for non-annoymous users) Hope that makes enough sense. Echoing values is your best friend when if else statements aren't working

[edit] Also make sure you aren't an anonymous user, or else your code is working fine. Just a case of a human not working correctly (just did that yesterday as well)

Liam