2013-12-12 104 views
0

快速版本:如何在視圖模板中輸出分類術語ID?我只想要數字ID值。這將被用作鏈接錨點。Drupal - 視圖 - 分類術語ID - 自定義模板 - 錨點

龍版本:

情景,我有這顯示分類術語列表的視圖。這個觀點有一個頁面和一個塊。頁面視圖設置爲將塊視圖顯示爲標題。該塊視圖只包含分類名稱。頁面視圖顯示所有的分類內容。

我想塊視圖列表錨定在頁面視圖中的項目:

Category page screenshot

這一觀點已經建成,方程的缺失部分越來越到位的錨鏈接。

視圖目前包括3個自定義模板文件:

視圖視場 - 類別 - page.tpl.php中

<article id="NEED THE TERM ID HERE"> 
    <header> 
    <h2 class="flag-heading"><?php print $fields['name']->content; ?> <span>in association with <?php print $fields['field_sponsor']->content; ?> </span></h2> 
    </header> 
    <div class="table"> 
    <div class="table-cell"> 
     <?php print $fields['field_category_image']->content; ?> 
    </div> 
    <div class="table-cell"> 
     <?php print $fields['description']->content; ?> 
    </div> 
    </div> 
</article> 

視圖視場 - 類別 - 塊.tpl.php

<li><a href="NEED THE TERM ID HERE"><?php print $fields['name']->content; ?></a></li> 

視圖視圖 - 類別 - block.tpl.php

<ul> 
    <?php print $rows; ?> 
</ul> 

我試過使用視圖上下文過濾器重寫頂部塊視圖鏈接,沒有運氣。

所有我需要的是TERM ID的變量 - 我已經做了可用變量的var轉儲,我可以看到該列表中的TID,但不知道如何在views-view-字段模板文件,並且可以找到任何網上沒有回答這個最簡單的概念。

頁和塊視圖設置的截圖:

Block view Page view

回答

0

添加

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

應該給你的意見,視場的TID - XXX - 頁。 tpl.php和--block.tpl.php

確保字段設置爲刪除任何默認包裝和你應該很好走。

+0

這最後有一個未定義的索引 - 嘗試了這條路線,但無論如何感謝。 –

2

終於贏得了我的觀點,這個跳轉列表是完全多餘的,愚蠢的,所以它會被刪除,但是,我還是設法輸出的TID,這是相當明顯,因爲這些東西往往是...

視圖視場 - 類別 - block.tpl.php

<li> 
    <a href="#cat<?php print($view->result[$view->row_index]->tid); ?>"><?php print $fields['name']->content; ?></a> 
</li> 

視圖視場 - 類別 - page.tpl。php

<article id="cat<?php print($view->result[$view->row_index]->tid); ?>"> 
    <header> 
    <h2 class="flag-heading"><?php print $fields['name']->content; ?> <span>in association with <?php print $fields['field_sponsor']->content; ?> </span></h2> 
    </header> 
    <div class="table"> 
    <div class="table-cell"> 
     <?php print $fields['field_category_image']->content; ?> 
    </div> 
    <div class="table-cell"> 
     <?php print $fields['description']->content; ?> 
    </div> 
    </div> 
</article> 

該變量顯然是在視圖數組中,這只是獲取當前視圖項索引的一種情況。