开发者

Drupal 7 inject div into existing structure

开发者 https://www.devze.com 2023-03-07 17:07 出处:网络
I am using drupal 7 views-view--myview.tpl.php sample 开发者_如何学运维code <?php if ($rows): ?>

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消