У меня есть функция в template.php, которая, помимо прочего, должна извлекать циклом картинки из поля imagecache и передавать в шаблон node.tpl.php
Вот кусок кода, что у меня есть в template.php
<?php
function small_images($node) {
global $base_path;
$index = 0;
foreach ($node->field_image_cache as $image) {
$index++;
$filepath = $image['filepath'];
$alt = $image['data']['alt'];
$title = $image['data']['title'];
if ($index > 0) {
$output = '<div class="image-thumb"><a href="'.$base_path.$filepath.'" alt="'.$alt.'" title="'.$title.'">'.theme('imagecache', 'uc_thumbnail', $filepath, $alt, $title).'</a></div>';
}
}
return $output);
}
?>
<?php
echo small_images($node)
?>
в node.tpl.php
выдаёт всего одно изображение вместо нескольких. В то же время, если этот цикл вставить напрямую в ноду, всё показывает как надо.
Как отображать все картинки? По ряду причин не хочу вставлять цикл напрямую в шаблоне.
Комментарии
<?php
foreach ($node->field_image_cache as $image) {
function small_images($node) {
global $base_path;
$index = 0;
$output = ''; // <--- fix
$index++;
$filepath = $image['filepath'];
$alt = $image['data']['alt'];
$title = $image['data']['title'];
if ($index > 0) {
$output .= '<div class="image-thumb"><a href="'.$base_path.$filepath.'" alt="'.$alt.'" title="'.$title.'">'.theme('imagecache', 'uc_thumbnail', $filepath, $alt, $title).'</a></div>'; // <--- fix
}
}
return
$output; // <--- fix}
?>
ух...
l() + theme('imagecache') и ничего более не надо
О, заработало, спасибо, точка перед равно рулит