cita / silverstripe-modular
CitaNZ的SilverStripe 4模块化方案
Requires
This package is auto-updated.
Last update: 2024-09-13 10:50:58 UTC
README
CitaNZ的SilverStripe模块化模块
要求: SilverStripe 4.0+
CitaNZ模块化是一个轻量级的模块,它使用ManymanyList
将页面和内容块链接起来,并使用“模块化”的概念构建网站。
它不仅允许用户在不同的页面上重用相同的块,而且当块类不可用时,也为开发者提供了一种安全措施(例如,删除的块子类将回退到Block::class
,而不是使CMS中的块编辑列表崩溃)。
安装
composer require cita/silverstripe-modular
sake dev/build flush=all
请确保在Web上也要执行/dev/build?flush=all
在类上启用模块化
请注意:如果页面的Content
字段已被使用,则千万不要启用此模块!!!
将$modulated
静态变量添加到类中
...
class SomePageType extends Page
{
...
private static $modulated = true;
...
}
然后刷新网站缓存(/?flush=all
)
构建您的模块化块
创建一个新类,并从Cita\Modular\Model\Block
扩展它
...
use Cita\Modular\Model\Block;
class MyShmartBlock extends Block
{
...
private static $icon_class = 'font-icon-block-content'; // choose an icon
private static $singular_name = 'Content block'; // singular name is also the block type
public function getPlain()
{
return 'Extract the text content on this block. It will be used for search purpose. If you are using your own search index implementation, then you don\'t need to worry about this';
}
public function getBlockSummary()
{
return 'Return a summary to explain what this block is about - this will be used on the block\'s gridfield';
}
}
允许/禁止块类型
以下行将仅允许页面上的BlockA::class
、BlockB::class
和BlockC::class
private static $allowed_modulars = [BlockA::class, BlockB::class, BlockC::class]
以下行将排除BlockA::class
、BlockB::class
和BlockC::class
作为可用的块类型
private static $disallowed_modulars = [BlockA::class, BlockB::class, BlockC::class]
前端
要打印模块化列表,只需将$Modulars
放置在需要它的.ss
文件中即可
<h1>The shmart page</h1>
$Modulars
模板化
当创建新的块子类时,将应用默认的块类模板(Cita\Modular\Model\Block
),以保持前端页面的连贯性。下一步是创建新子类的模板(确保它与正确的命名空间匹配),然后刷新浏览器缓存--现在您只需在模板文件中构建块HTML并使用前端技能进行样式设计。
覆盖CitaNZ模块化的默认模板
如果您需要调整默认块的HTML或更改模块化块在页面上的显示方式,请按照以下步骤操作
- cp -rf
vendor/cita/silverstripe-modular/templates/Cita
your_theme/templates/.
(替换为相应的your_theme
...) - 刷新(在浏览器上)
- 检查其中的
.ss
文件 - 做你的事
缓存
要为特定的块类型启用缓存,请将以下内容添加到块类型的类中
private static $cache_enabled = true;
并定义getCacheInvalidator
函数,并构建缓存应该何时失效的条件。
以下为默认的失效器
public function getCacheInvalidator()
{
$prefix = str_replace('\\', '_' , strtolower(__CLASS__));
return $prefix . '__' . ($this->exists() ? ($this->ID . '__' . strtotime($this->LastEdited)) : time());
}
它正在查看块类型、块ID和最后编辑的日期时间。
弹性块
弹性块提供了一种快速将不同的块分组到弹性row
中的方法。如果您在您的前端堆栈中使用Vuetify
或Bootstrap
或类似的东西,那么您需要做的只是设置CMS中的列大小。否则,您将不得不自行实现flexbox
。
有疑问吗?
问题:为什么你不...
答案:请提交pull request
问题:我需要做这样那样的...所以你能添加这个功能吗...等等...
答案:此模块旨在轻量级,所以让我们保持这种状态。我提供嗅探,但不做嗅探!(你肯定也不想那样!)