When using jcarousel with views I get Notice: Uninitialized string offset warnings for line 11 of the includes/jcarousel-view.tpl.php file if the number of nodes the view is displaying is greater than 14.

The error is due to $classes[$id] being empty - prior to that it id displaying consecutive letters in the string "jcarousel-view" - which has 14 letters.

While this doesn't effect the carousel and the notices are not shown with warnings switched off - it'd be great to fix this as is a pain in developer mode and also googling "jcarousel notice: Uninitialized string offset" brings up other sites that have this displayed so some users probably don't realize it's showing?

This is the fix I've used which works:

<ul class="<?php print $jcarousel_classes; ?>">
    <?php foreach ($rows as $id => $row): ?>
        <?php if (isset($classes[$id])) {  ?>
            <li class="<?php print $classes[$id]; ?>"><?php print $row; ?></li>
        <?php } else { ?>
            <li><?php print $row; ?></li>
        <?php } ?>
    <?php endforeach; ?>
</ul>

Is there a need for the $classes[$id] to be added?

CommentFileSizeAuthor
#3 jcarousel_classes_notice.patch1.01 KBquicksketch

Comments

ytsurk’s picture

confirmed temporary fix for the mentioned warnings

thx

joostvdl’s picture

Tried the fix also, which works.

quicksketch’s picture

Status: Active » Fixed
StatusFileSize
new1.01 KB

This is because D7 hijacks the variable name "classes for its own purposes, making it so contrib modules cannot use that same variable name. This patch corrects the problem by using the name $row_classes instead. Committed to D7 branch only.

quicksketch’s picture

Title: Uninitialized string offset warnings » Uninitialized string offset warnings in template variable $classes

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.