我如何允许用户在 silverstripe CMS 中设置自定义全局值?

How can I allow the user to set a custom global value in the silverstripe CMS?

我希望能够在 CMS 中设置自定义值,例如网站名称和标语。除了在单独的页面上,我目前找不到任何方法来执行此操作。

您可以通过扩展 SiteConfig 来实现。您的扩展可能如下所示:

class CustomSiteConfig extends DataExtension
{
    private static $db = array(
        'CustomContent' => 'Varchar(255)'
    );

    public function updateCMSFields(FieldList $fields)
    {
        $fields->addFieldToTab('Root.Main',
            TextField::create('CustomContent', 'Custom content')
        );
    }
}

然后您需要将扩展​​名应用到 SiteConfig。将以下内容添加到 mysite/_config/config.yml

SiteConfig:
  extensions:
    - CustomSiteConfig

就是这样。 运行 dev/build 并且您的新字段应该可以在 CMS 中编辑,并且可以使用以下方法在模板中访问:$SiteConfig.CustomContent