2

I'm using Drupal 7, and Views 3.

I would like to reproduce my comment template in views-view-fields.tpl.php.

Thus I need to print my fields to be able to arrange them as I wish it.

For each field, I proceed like that : <?php print $view->render_field('field_name', $id);?>, is it the correct/secure way ?

I don't think so, because all the row does not display.

1

The correct way is:

<?php print $fields["field_name"]->content; ?>

Note: Using views-view-fields.tpl.php will affect all of your views, which you may not want.

To target a specific view you need to use:

views-view-fields--[view-name]--[machine-name].tpl.php

5
  • It works, but I have now for every field an error of type: Notice : Trying to get property of non-object dans include() and Notice : Undefined index: namefield dans include() Do you know where from it can come?
    – Hgfdsoiu
    Oct 25 '16 at 13:51
  • Did you name your template like this views-view-fields--[view-name]--[machine-name].tpl.php ?
    – No Sssweat
    Oct 25 '16 at 13:55
  • Yes. I think that this problem appears when I disconnect. Fields indeed appear only when the users are connected. I would have to include in the views template a condition of type "if" i think
    – Hgfdsoiu
    Oct 25 '16 at 13:57
  • But I do not know the syntax. I try this <?php if ($fields["field_name"]->content;): ?> but it does not work
    – Hgfdsoiu
    Oct 25 '16 at 14:00
  • Are you trying to check if it exists? You don't need the ; inside the bracket, if it still does not work after deleting the ; try <?php if (isset($fields["field_name"]->content)): ?> something goes here <?php endif; ?>
    – No Sssweat
    Oct 25 '16 at 14:37

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.