Добавить first-item и last-item
7 апреля 2012 в 21:43
Добрый вечер! Скажите, есть ли в друпале функция которая добавляет например в массив из DIVов class="first-item" и "last-item" так как это делает VIEWS.
- Блог
- Войдите или зарегистрируйтесь, чтобы отправлять комментарии
Комментарии
см. theme_item_list
theme_item_list создает в списке. А views выводит просто дивы и добавляет к ним классы.
Совершенно верно.
Ну а есть ли такая функция?
Такой функции нет. Но есть подобные о которой я Вам написал.
Тоесть у views своя похожая функция. Не использует функцию друпала.
<?php
$columns = $options['columns'];
$rows = array();
/**
* Display a view as a grid style.
*/
function template_preprocess_views_view_grid(&$vars) {
$view = $vars['view'];
$result = $view->result;
$options = $view->style_plugin->options;
$handler = $view->style_plugin;
if (
$options['alignment'] == 'horizontal') {$row = array();
$row_count = 0;
foreach ($vars['rows'] as $count => $item) {
$row[] = $item;
$row_count++;
if (($count + 1) % $columns == 0) {
$rows[] = $row;
$row = array();
$row_count = 0;
}
}
if ($row) {
// Fill up the last line only if it's configured, but this is default.
if (!empty($handler->options['fill_single_line']) || count($rows)) {
for ($i = 0; $i < ($columns - $row_count); $i++) {
$row[] = '';
}
}
$rows[] = $row;
}
}
else {
$num_rows = floor(count($vars['rows']) / $columns);
// The remainders are the 'odd' columns that are slightly longer.
$remainders = count($vars['rows']) % $columns;
$row = 0;
$col = 0;
foreach ($vars['rows'] as $count => $item) {
$rows[$row][$col] = $item;
$row++;
if (!
$remainders && $row == $num_rows) {$row = 0;
$col++;
}
else if ($remainders && $row == $num_rows + 1) {
$row = 0;
$col++;
$remainders--;
}
}
for ($i = 0; $i < count($rows[0]); $i++) {
// This should be string so that's okay :)
if (!isset($rows[count($rows) - 1][$i])) {
$rows[count($rows) - 1][$i] = '';
}
}
}
// Add first/last column class
foreach ($rows as $row_number => $row) {
foreach ($row as $column_number => $column) {
$column_classes[$row_number][$column_number] = 'col-' . ($column_number + 1);
if ($column_number == 0) {
$column_classes[$row_number][$column_number] .= ' col-first';
}
elseif (count($rows[$row_number]) == ($column_number + 1)) {
$column_classes[$row_number][$column_number] .= ' col-last';
}
}
}
$vars['column_classes'] = $column_classes;
$vars['rows'] = $rows;
$vars['class'] = 'views-view-grid col-' . $columns;
$vars['attributes'] = '';
if (!empty($handler->options['summary'])) {
$vars['attributes'] = drupal_attributes(array('summary' => $handler->options['summary']));
}
}
?>