0

I tried to print the Image field URI and the image field in the views-field.tpl and i got this error. Notice: Undefined index: field_photo in include() (line 6 of timeline.tpl.php). Notice: Trying to get property of non-object in include() (line 6 of timeline.tpl.php).

Here is my code

<li class="row no-margin">
    <div class="timeline-badge <?php print $fields['field_event']->content ?>" data-toggle="tooltip" data-placement="top" title="<?php print $fields['field_event']->content ?>"><?php print $fields['field_icon']->content ?></div>
    <div class="timeline-panel">
        <div class="timeline-mins"><?php print $fields['field_minute']->content ?></div>    
        <div class="timeline-comment"><?php print $fields['field_comment']->content ?></div>
        <?php if($fields['field_photo']->content){  ?>
        <div class="timeline-photo">
        <a id="tml-photo" href="<?php  print $fields['uri']->content; ?>" title="<?php print $fields['field_comment']->content ?>">
        <?php print $fields['field_photo']->content ?>
        </a>    </div>
        <?php } ?>
    </div>
</li>
0

If you just want to check if it has a value, you can add a check if it exists, so on row 6:

<?php if (isset($fields['fields_photo']->content) && $fields['fields_photo']->content) { ?>

Otherwise do a <?php dpm($fields); ?> to see what is actually available to use for your theme.

It couldn't be that you have set it to "Exclude from display"?

0

For line 6, try:

<?php if(!empty($fields['field_photo']->content)){  ?>

or

<?php if($fields['field_photo']->content != NULL){  ?>

The above two codes checks if the field is not empty, which means it exists.

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.