I have a node template that prints out the value of my piwik stats field as such:

print render($content['field_year']['#items'][0]['nb_hits']);

However since a value doesn't exist for that field before cron run I get an error as such:

Notice: Undefined index: field_year in include() (line 41 of /home/folioh/public_html/sites/all/themes/folioh3/templates/node--image.tpl.php).

What can we do about this? Can we fill the values with 0 which will then be updated on cron?

Comments

patrickd’s picture

Status: Active » Postponed (maintainer needs more info)

As I see this, that's just normal for a field with no values, just always check with isset before accessing array elements

if (isset($content['field_year']['#items'][0]['nb_hits'])) {
  print render($content['field_year']['#items'][0]['nb_hits']);
}

or is there a problem with that?

infines’s picture

Status: Postponed (maintainer needs more info) » Closed (works as designed)

Duh. Sorry. :P I'm using a lot of if statements as well so I tend to skip sometimes.