Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment #1
patrickd CreditAttribution: patrickd commentedAs I see this, that's just normal for a field with no values, just always check with isset before accessing array elements
or is there a problem with that?
Comment #2
infines CreditAttribution: infines commentedDuh. Sorry. :P I'm using a lot of if statements as well so I tend to skip sometimes.