0

There is a view and content type both called activities and this is views-view-fields--activities--block.tpl.php

<div class="element">
<div class="image"><?php print $fields['field_activities_image']->content;?></div>
<div class="text">
    <div class="head"><?php print $fields['field_activities_title']->content;?>    </div>
    <div class="body"><?php print $fields['field_activities_summary']->content;?>    </div>
</div>
</div>

this block is displayed in the front--page.tpl.php and it works right. There is another block of this view and that block is displayed in the node page. this block only contains 10 title. the problem is drupal reports this warning in the node page:

Notice: Undefined index: field_activities_image in include() (line 2 of ...views-view-fields--activities--block.tpl.php)
Notice: Undefined index: field_activities_summary in include() (line 5 of ...views-view-fields--activities--block.tpl.php)
Notice: Undefined index: field_activities_image in include() (line 2 of ...views-view-fields--activities--block.tpl.php)
Notice: Undefined index: field_activities_summary in include() (line 5 of ...views-view-fields--activities--block.tpl.php)
Notice: Undefined index: field_activities_image in include() (line 2 of ...views-view-fields--activities--block.tpl.php)
Notice: Undefined index: field_activities_summary in include() (line 5 of ...views-view-fields--activities--block.tpl.php)
Notice: Undefined index: field_activities_image in include() (line 2 of ...views-view-fields--activities--block.tpl.php)
Notice: Undefined index: field_activities_summary in include() (line 5 of ...views-view-fields--activities--block.tpl.php)
Notice: Undefined index: field_activities_image in include() (line 2 of ...views-view-fields--activities--block.tpl.php)
Notice: Undefined index: field_activities_summary in include() (line 5 of ...views-view-fields--activities--block.tpl.php)
Notice: Undefined index: field_activities_image in include() (line 2 of ...views-view-fields--activities--block.tpl.php)
Notice: Undefined index: field_activities_summary in include() (line 5 of ...views-view-fields--activities--block.tpl.php)

The ID of the block that is displayed in the node page is block_1 but it tries to use views-view-fields--activities--block.tpl.php. how can I solve this warning?

2
  • What var_dump($fields) shows you? Is this index defined at all? what was in auto-generated comment in the generated views-view-fields--activities--block.tpl.php file?
    – Mołot
    Commented Feb 14, 2014 at 9:11
  • like I said there are two blocks of activities view, block and block_1. block contains the above mentioned fields but block_1 only contains field_activities_title. var_dump($fields) displays the fields in the front page, but summary and image is not in the block_1 that's why it reports this warning in the node page. block_1 is not in the front page and there is no warning in there.
    – M a m a D
    Commented Feb 14, 2014 at 9:28

1 Answer 1

3

I think that the name views-view-fields--activities--block.tpl.php is a suggestion for all blocks of the view activities - to get better specified template name check template information in that view. ('Information' link under Other -> Theme in the view builder) I think that the template name should be something like views-view-fields--activities--[block_id].tpl.php.

Change the block machine name if necessary.

Also, its a good practice to utilise this in templates to prevent such warnings:

<?php if (!empty($fields['field_activities_image'])):?>
  <div class="image"><?php print $fields['field_activities_image']->content;?></div>
<?php endif; ?>
2
  • Yes you are right, views-view-fields--activities--block.tpl.php is shared among all of the blocks
    – M a m a D
    Commented Feb 14, 2014 at 9:31
  • yeah so change the block machine name to distinguish it.
    – m1n0
    Commented Feb 14, 2014 at 9:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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