flxlabs / silverstripe-pagesections
为您的 SilverStripe 项目添加可配置的页面部分和元素。
1.1.0
2024-04-30 11:38 UTC
This package is auto-updated.
Last update: 2024-08-30 12:16:35 UTC
README
可配置页面部分和元素的 Elemental 替代方案。
简介
此模块为 SilverStripe 4.x 项目提供页面部分。页面部分是页面上用户可以以结构化方式添加内容的区域。页面可以没有、一个或多个页面部分。每个页面部分由各种页面元素组成,这些元素本身可以或不可以有其他页面元素作为子元素。
安装
composer require flxlabs/silverstripe-pagesections
将扩展添加到应包含页面部分的 DataObject
Page: extensions: - PageSectionsExtension
默认情况下,DataObject 将有一个名为 Main
的页面部分。要添加额外的部分或更改默认部分的名称,请指定它们在 page_sections
键中。
Page: extensions: - PageSectionsExtension page_sections: - Main - Aside
请确保运行 dev/build
并刷新。
使用方法
定义一个元素
<?php class TextElement extends FLXLabs\PageSections\PageElement { public static $singular_name = 'Text'; public static $plural_name = 'Texts'; private static $db = [ 'Content' => 'HTMLText', ]; // Page elements can have other page elements as children. // Use this method to restrict allowed childre. public function getAllowedPageElements() { return [ // YourElement::class ]; } // This will be used to preview the content in the CMS editor public function getGridFieldPreview() { return $this->dbObject('Content')->Summary(); } }
要渲染一个元素,创建一个模板。要渲染页面部分,使用 PageSectionsExtension 提供的 RenderPageElements
方法。
<div> $RenderPageSection('SectionName') </div>