简体   繁体   中英

Drupal 7 inject div into existing structure

I am using drupal 7

views-view--myview.tpl.php sample code
<?php if ($rows): ?>
<?php print $rows; ?>

When i see this in firebug i see the structure
<div class="item-list">
<ul>
<li class="views-row views-row-1 views-row-odd views-row-first"> </li>
<li class="views-row views-row-2 views-row-even "> </li>

Now how do i inject a div in each of these li.. Is this possible without using jquery?

If you go the the "Edit" page for the view, you should see a link called " Theme: Information ". It's under the " Style Settings " section. If you click this, you can see a list of all the possible template that your theme will look for when displaying the view. In bold will be the file it is currently using.

views-view--myview.tpl.php is to high up the chain to do what you want. If you want to inject a div (the same div) around each field you output, then I think the file views-view-field.tpl.php is what you are looking for.

The file contains just the line

<?php print $output; ?>

So there you can insert the desired div (after you copy it from views/themes into the template directory for your theme, of course).

If you investigate the Theme Information link some more it describes how to be even more specific in naming the view template files, for example if you wanted to theme a specific row differently you could use the file views-view-field--entity-id-X .

Hope that helps!

EDIT for comment

To go a different route, you can also edit the field settings for your view. Under the Field tab on the edit view page, you can click the links for each field. There is a Suffix setting available you could use to inject a div after the field is displayed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM