I have this snippet:
<?php
$filename= $modx->documentObject['description'];
$filename_close = 'assets/images/species/'.$filename.'/'.$filename.'_close.jpg';
$filename_hole= 'assets/images/species/'.$filename.'/'.$filename.'_hole.jpg';
$filename_place= 'assets/images/species/'.$filename.'/'.$filename.'_place.jpg';
if (file_exists($filename_close)) {
echo '<td valign="top" width="183px" height="100%"><a href="assets/images/species/'.$filename.'/'.$filename.'_close_full.jpg" title="Click to get a larger image" rel="lightbox">
<img class="close" src="'.$filename_close.'" />
<p class="hide">
Place: [*location-close*]<br />
© [*photo-close*]
</p>
</a>
</td>';
} else {
echo '<td valign="top" width="183px" height="100%" class="noHover"> No picture yet. </td>';
}
if (file_exists($filename_hole)) {
echo '
<td valign="top" width="158px" class="hole"><a href="assets/images/species/'.$filename.'/'.$filename.'_hole_full.jpg" title="Click to get a larger image" rel="lightbox">
<img class="hole" src="'.$filename_hole.'" />
<p class="hide">
Place: [*location-hole*]<br />
© [*photo-hole*]
</p>
</a>
</td>';
} else {
echo '<td valign="top" width="158px" class="noHover"> No picture yet. </td>';
}
if (file_exists($filename_place)) {
echo '
<td valign="top" width="227px" class="place"><a href="assets/images/species/'.$filename.'/'.$filename.'_place_full.jpg" title="Click to get a larger image" rel="lightbox">
<img class="place" src="'.$filename_place.'" />
<p class="hide">
Place: [*location-place*]<br />
© [*photo-place*]
</p>
</a>
</td>';
} else {
echo '<td valign="top" class="noHover"> No picture yet. </td>';
}
?>
The snippet works when it’s called directly from the template. (Example
here) But the
if (file_exists($filename_close)) { doesn’t work when called from a tpl-file in a Ditto call.
Here is the Ditto tpl:
<tr>
<td class="listDataCell"><a href="[~[+id+]~]">[+pagetitle+]</a></td>
<td class="listDataCell">[+norwegian+]</td>
<td align="center" class="listDataCell">[+redlist-wrapper:len:gt=`0`:then=`<strong style="color: red;">R</strong>`:else=``+]</td>
[[getListPictureFiles]]
</tr>
and here is the code in getListPictureFiles:
<?php
$filename= $modx->documentObject['description'];
$filename_close = 'assets/images/species/'.$filename.'/'.$filename.'_close_mini.jpg';
$filename_hole= 'assets/images/species/'.$filename.'/'.$filename.'_hole_mini.jpg';
if (file_exists($filename_close)) {
echo '
<td class="imageCell" width="30px"><img class="listImgLeft" src="'.$filename_close.'" /></td>';
} else {
echo '<td class="imageCell" width="30px">No picture yet</td>';
}
if (file_exists($filename_hole)) {
echo '
<td class="imageCell" width="32px"><img src="'.$filename_hole.'" /></td>';
} else {
echo '<td class="imageCell" width="32px">No picture yet</td>';
}
?>
Here is the original side, without the file-exists test.
And
here is the side with the file-exists-test that doesn’t work.