我正在使用SilverStripe而且我遇到了一个问题。
我创建了自定义NewsPage
页面类型和News
DataObject
:
NewsPage
class NewsPage extends Page
{
private static $has_many = array(
'News' => 'News'
);
public function getCMSFields()
{
$fields = parent::getCMSFields();
$gridFieldConfig = GridFieldConfig::create()->addComponents(
new GridFieldToolbarHeader(),
new GridFieldAddNewButton('toolbar-header-right'),
new GridFieldSortableHeader(),
new GridFieldDataColumns(),
new GridFieldPaginator(10),
new GridFieldEditButton(),
new GridFieldDeleteAction(),
new GridFieldDetailForm(),
new GridFieldBulkManager()
);
$gridField = new GridField(
'News',
'All News Entries',
$this->News(),
$gridFieldConfig
);
$fields->addFieldToTab('Root.News', $gridField);
return $fields;
}
}
class NewsPage_Controller extends Page_Controller
{
}
新闻
class News extends DataObject
{
private static $db = array(
'Title' => 'Text',
'Description' => 'HTMLText'
);
private static $has_one = array(
'NewsPage' => 'NewsPage',
'NewsImage' => 'Image'
);
private static $summary_fields = array(
'Title' => 'Title',
'NewsImage'=> 'NewsImage',
'Description'=> 'Description'
);
public function getCMSFields()
{
$fields = new FieldList(
new TextField('Title', 'Title'),
new UploadField('NewsImage', 'NewsImage'),
new HTMLEditorField('Description', 'Description')
);
return $fields;
}
}
现在我想在我的主页上显示最新消息,但我不知道如何使用短代码显示它。
以下是CMS的屏幕截图。在这里,您可以使用短代码查看我想在主页上显示的新闻部分。