In a template, I'm drawing a 4x3 table that I want to display images from other pages selected from page fields inside a repeater on this page. Their position relative to each other is important, and most of the space in the table will usually be intentionally empty, which is why I'm doing it in this rather strange way:
In the admin, the referenced page's image's position in the table is chosen from page selects with columns and rows defined in /global/matrix/rows/ and /global/matrix/cols/. In the template, we get the images by iterating through the table and seeing if any of the "ingredient" items on this page match the the coordinates of the current table cell.
If what I've described here sounds confusing, it's confusing me, too.
Here's my loop:
foreach ($pages->get("/global/matrix/rows/")->children as $row) {
echo '<tr>';
foreach ($pages->get("/global/matrix/cols/")->children as $col) {
$tdobject = $page->ingredients->find("m_row=$row, m_col=$col")->first()->ingredient;
echo '<td><img src="'. $tdobject->icon->size(40, 40)->url . '"/></td>'; // line that throws the error
}
echo '</tr>';
}
This gets me:
Error Call to a member function size() on a non-object
However, changing that line to this works:
echo '<td><img src="'. $tdobject->icon->url . '"/></td>';
So I can pull a URL from the image object on the referenced page, but I can't call size() on it. What am I missing?