簡體   English   中英

將唯一的ID添加到Drupal Views列表分組

[英]Add a unique ID to Drupal Views list groupings

我正在使用Drupal 7中的Views 3輸出字段列表,並使用分組字段來生成單獨的列表。 我需要每個分組都將唯一的ID屬性應用於<ul>,但默認情況下不是。

據我所知,我需要編輯views-view-list.tpl.php模板,但我不知道如何在每次迭代中獲得唯一的ID。

有人可以幫忙嗎?

供將來參考:將div放在view-views-list.tpl.php中。 您可以(ab-)使用$ title生成唯一(但一致)的ID。

像這樣做:

<?php $id = str_replace('FOR ALL UNWANTED CHARS','',$title); ?>

<div id="<?php print strtolower($id); ?>">

您可以使用$ view-> dom_id變量。 這是該視圖實例的唯一ID。

在您的.tpl.php文件中:

<?php print $view->dom_id; ?>

從modules \\ views \\ theme \\ theme.inc中的注釋中:

<?php
    // It is true that the DIV wrapper has classes denoting the name of the view
    // and its display ID, but this is not enough to unequivocally match a view
    // with its HTML, because one view may appear several times on the page. So
    // we set up a hash with the current time, $dom_id, to issue a "unique" identifier for
    // each view. This identifier is written to both Drupal.settings and the DIV
    // wrapper.
?>

我可以想到的最簡單的方法...

<?php print $wrapper_prefix; ?>
  <?php if (!empty($title)) : ?>
    <h3><?php print $title; ?></h3>
  <?php endif; ?>
  <ul id="<?php echo uniqid(); ?>">
    <?php foreach ($rows as $id => $row): ?>
      <li class="<?php print $classes_array[$id]; ?>"><?php print $row; ?></li>
    <?php endforeach; ?>
  </ul>
<?php print $wrapper_suffix; ?> 

它將放在您的views-view-list.tpl.php文件中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM