【问题标题】:How do I stack CMS field labels in silverstripe?如何在 silverstripe 中堆叠 CMS 字段标签?
【发布时间】:2017-12-12 18:55:37
【问题描述】:

我正在 SilverStripe 4 中创建自定义 CMS 字段,它们是使用左列中的标签和右列中的编辑器构建的。

查看图片:

如何像图片中看到的默认内容编辑器和标签一样堆叠标签和编辑器?

【问题讨论】:

    标签: silverstripe silverstripe-4


    【解决方案1】:

    所以我在寻找其他东西时终于找到了答案。我会回答我自己的问题,以防有人在未来寻找同样的东西,因为寻找 Silverstripe 问题的答案很困难。

    在文档中说要为额外的所见即所得编辑器执行此操作

    return new FieldList([
        new HTMLEditorField('OtherContent', 'Other content', $this->OtherContent, 'myConfig')
    ]);
    

    我们将把它分解成组件以给予我们更多的控制权

    $fields = parent::getCMSFields();
    //create a $fields variable that will hold the new fields
    
    $jobDescriptionField = HTMLEditorField::create('JobDescription', 'JobDescription');
    //create the actual field in it's own variable
    
    $fields->addFieldToTab('Root.Main', $jobDescriptionField , 'Content');
    //add the new field to our fields and tell it to appear above the default 'Content' editor
    

    如果我们停在这里并返回 $fields,我们将让标签浮动到左边,内容编辑器浮动到右边。即使在全屏上它也会被压扁。不好。

    所以我们需要添加一个由 silverstripe 提供的名为“stacked”的类

    $jobDescriptionField->addExtraClass('stacked');
    

    所以完整的代码如下:

    public function getCMSFields(){
        $fields = parent::getCMSFields();
    
        $jobDescriptionField = HTMLEditorField::create('JobDescription', 'JobDescription');
    
        $fields->addFieldToTab('Root.Main', $jobDescriptionField , 'Content');
    
        $jobDescriptionField->addExtraClass('stacked');
        return $fields;
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-08
      • 2023-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多