How to properly tag topic fields in Drupal 7

I need to view themes in Drupal 7. There is a "Book" content type and I need to list 5 books and their topic in a special way (preview image, title and author).

When I override view-view-field.tpl.php and print the original SQL result, I see that all fields are displayed. This code

echo "<pre>";
print_r($row);
echo "</pre>";

      

gives

[entity] => stdClass Object
 (
  [title] => ...
  ....
  [nid] => 34
  ...
  [body] => Array
  ...

      

But I don't want to pass the [body] from the database to php because it can be huge and cause a performance problem. I have not selected [body] in the view settings.

Is there a way to only pass certain fields to view-view-field.tpl.php?

Thanks in advance.

+3


source to share


4 answers


If what you want to do is theme of a specific field, you can create a template for that specific field like this: view-view-field - field-nameofmyfield.tpl.php put it in the theme folder and search for templates again in section "Subject: Information" in the "View" configuration.



For this you need to add a field to the fields in the view.

+3


source


The available variables are recorded in the documentation inside the files in the sites / all / modules / views / theme folder.

Usually the variable that needs to be viewed and changed in the views-view-fields.tpl.php template is $ fields

I am using the devel module (http://drupal.org/project/devel) to view the available variables:

<?php
//after enabling the devel module...
dpm($fields);

// This will print a Kuomo display on the page with the array vars

?>

      

In general, in terms of nodes,

<?php print $fields['title']->content; ?> 

      



will print the header node. For fields try

<?php print $fields['field_FIELDNAME']->content; ?>

      

If you have memory, you can grab ALL YOU available on the template in Goomo with

<?php dpm(get_defined_vars()); ?>

      

Make sure you clear your cache before trying to view vars.

+4


source


To sort your information in a topic use this:

<?php dpm ($rows); ?> // View all the information in the view

<?php foreach ($rows as $row_count => $row): ?>
 <?php print $row['title'];
 <?php print $row['nid'];
<?php endforeach; ?>

      

0


source


If you want to change the view theme, then change views-view-fields.tpl.php as follows:

<div class="pagecontent">
    <div class="colleft">
        <?php if($fields['field_file']->content){  ?><div class="views-field-file"><?php print $fields['field_file']->content; ?></div><?php } ?>
    </div>
    <div class="colright">
        <div class="views-field-title"><?php print $fields['title']->content; ?></div>
        <div class="views-field-body"><?php print $fields['body']->content; ?></div>
        <div class="views-field-view-node"><?php print $fields['view_node']->content; ?></div>
    </div>
</div>

      

0


source







All Articles