开发者

Drupal Views - for user: id field, match content against an array

I have an array of user ids and I need to go through the a user: id field within a view, adding a bit of specific HTML for matching and non-matching results.

So I'm guessing something like this needs to go in views-view-field--uid.tpl.php:

<?php if (//Field content matches an array value): ?>
<span class="friend"><?php print $output; ?></span>
<?php endif; ?开发者_运维百科>

<?php if (//Field content doesn't match an array value): ?>
<span class="not-friend"><?php print $output; ?></span>
<?php endif; ?>

Can someone help me fill in the gaps, please? :)


Assuming $ouput is going to be only an integer representing the uid (and not HTML markup), you could do something like this:

<span class="<?php if(!in_array($output, $your_array)): ?>not-<?php endif; ?>friend">
    <?php print $output; ?>
</span>

see php in_array()

However, $output might be HTML. If that's the case you should use $row instead of $output. To see what $row contains I love doing this in template files:

<!-- <?php echo print_r($row,true); ?> -->

(then view source in browser)

Also, I'd recommend not doing this at all in your template file because it ties logic to the theme... Check out Views Customfield -- it will let you do PHP in a custom field... If you put it under the UID, and exclude UID from display, you can access the UID and execute the same code I've got above in the custom field, using the $data object instead of $row or $output.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜