2011-04-17 27 views
0

我有一個用戶ID數組,我需要通過視圖中的user: id字段,爲匹配和不匹配添加一些特定的HTML結果。Drupal Views - 對於用戶:ID字段,與數組匹配內容

所以我猜是這樣的需要的觀點視場去 - 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; ?> 

有人可以幫我填補空白嗎? :)

回答

2

假設$輸出中會是隻表示UID的整數(而不是HTML標記),你可以做這樣的事情:

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

看到php in_array()

然而,$輸出可能是HTML。如果是這種情況,您應該使用$ row而不是$ output。 要查看$行包含我喜歡在模板文件這樣做:

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

(然後查看瀏覽器源)

另外,我建議你這樣做並不是在所有的,因爲它的模板文件將邏輯關聯到主題...檢出Views Customfield - 它可讓您在自定義字段中執行PHP ...如果將其置於UID下,並將UID從顯示中排除,則可以訪問UID並執行相同的代碼我已經在自定義字段中使用了$ data對象而不是$ row或$ output。

+0

很酷,這很有用。乾杯! – james6848 2011-04-17 21:11:16