I am trying to use the field data inside of a views template to modify its output. I looked at the available fields with devel, and, inside of a field template, I used the following code:


and many more like this. It worked fine. The only issue is that the page was giving me a lot of notice message from this code:

*   Notice: Undefined offset: 0 in include() (line 28 of [path-to-file].tpl.php).

Is this not the correct way to get data? If so, what is it?


It shows you the Notice because somewhere in your data array you have missing data for a specific node. As for being correct, yes, it is a good way to alter the output. Try checking the data before printing it.

Something like

if(isset($row->field_field_twitter_screen_name[0]['rendered']['#markup'])) {
  //do custom action here

Edit: You can also make good use of $content variable here.

  • what is the content variable, and why don't I see it listed on the template instructions? All I see is $view, $field, $row, $output. – user1015214 Sep 12 '13 at 14:27
  • $content is a variable that contains the content of a page, if you are using a tpl.php, you can access it. Are you using Devel module? if yes try dpm($content); to display the variable structure, if not try echo '<pre>'; print_r($content); echo '</pre>'; – Dragos Damian Sep 12 '13 at 14:30
  • I tried it inside of a field template and it came back blank. Is it available in this template? Why wouldn't be listed as an available variable? – user1015214 Sep 12 '13 at 14:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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