Feeling a little stupid here, I'm hoping this is just something new in SS4 that I'm unaware of and not just my advanced age getting the better of me...
I have an UploadField in my DataObject. But when I loop through it in my template I can't get the Image to display.
MyPage.php:
<?php
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Forms\GridField\GridFieldConfig_RecordEditor;
use UndefinedOffset\SortableGridField\Forms\GridFieldSortableRows;
class MyPage extends Page {
private static $has_many = array(
'MyObjects' => MyObject::class
);
...
MyObject.php:
<?php
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\ORM\DataObject;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\TabSet;
use SilverStripe\Forms\TextField;
use SilverStripe\AssetAdmin\Forms\UploadField;
use SilverStripe\Assets\Image;
use SilverStripe\AssetAdmin\Forms\PreviewImageField;
class MyObject extends DataObject {
private static $db = array(
'Title' => 'Varchar(255)'
);
private static $has_one = array(
'MyImage' => Image::class,
'MyPage' => MyPage::class
);
public function getGeneratedCMSFields() {
$fields = FieldList::create(TabSet::create('Root'));
$fields->addFieldToTab('Root.Main', TextField::create('Title', 'Title'));
$fields->addFieldToTab('Root.Main', $img = UploadField::create('MyImage', 'My Image'));
$img->getValidator()->setAllowedExtensions = array('jpg', 'jpeg', 'gif', 'png');
$fields->removeFieldFromTab('Root.Main', 'MyPageID');
return $fields;
}
public function getCMSFields() {
$fields = $this->getGeneratedCMSFields();
return $fields;
}
}
MyPage.ss:
<% loop $MyObjects %>
<h1>$Title</h1>
<% with $MyImage %><img src="{$URL}" title="{$Up.Title}"><% end_with %>
<% end_loop %>
This prints out the $Title and alt img tag as expected, but no image. I've even tried to reduce the complexity to simply <% loop $MyObjects %> $MyImage <% end_loop %> and still no image. What am I missing?