我有一个页面类型
产品页面
那 $has_one FeatureImage
有一个引用 ProductPages 之一的虚拟页面
当我在一个循环子项的页面中时,其中一个子项是虚拟页面,我可以呈现除 FeatureImage 字段之外的所有字段。
class ProductPage extends Page
{
private static $db = [
'TeaserText'=>'Varchar'
];
private static $has_one = [
'LinkedProduct'=>'Product',
'FeatureImage'=>Image::Class
];
private static $many_many = [
];
private static $owns = [
'FeatureImage'
];
public function getCMSFields(){
$fields = parent::getCMSFields();
$featureField = UploadField::create('FeatureImage', 'Feature Image')->setFolderName('FeatureImages')->setDescription("This image appears in the category pages. 400x400px");
$teaserField = TextField::create('TeaserText', 'Teaser Text')->setDescription("This text appears in the category pages");
$fields->addFieldToTab('Root.Main', $featureField, 'Metadata');
$fields->addFieldToTab('Root.Main', $teaserField, 'Metadata');
$productLinkField = DropdownField::create('LinkedProductID', 'Link a Product', Product::get()->map('ID', 'ProductName'));
$productLinkField->setEmptyString('(Select one)');
$fields->addFieldToTab('Root.Main', $productLinkField, 'Content');
$productLinkField->addExtraClass('stacked');
$featureField->addExtraClass("stacked");
$teaserField->addExtraClass("stacked");
return $fields;
}
}
SS 模板
<% loop $Children %>
<div class="category-card mb-5">
<div class="row">
<div class="col-md-4">
<img src="$FeatureImage.URL" class="fluid-image"/>
//This renders for standard ProductPage children
</div>
<div class="col-md-8 category-card-body">
<h4 class="category-card-title"><a href="$Link">$MenuTitle</a></h4>
<p class="category-card-text">$TeaserText</p>
//This TeaserText renders fine.
<a href="$Link" class="category-card-link btn btn-info">view details</a>
</div>
</div>
</div>
<% end_loop %>