SilverStripe wysiwyg图像在没有base_标记的情况下无法工作

SilverStripe wysiwyg图像在没有base_标记的情况下无法工作,silverstripe,Silverstripe,我已从模板中删除了base_标记。这样做的一个副作用是,主页以外的页面上的图像会中断 HTMLEditorField::saveInto()方法在图像上强制使用相对url,结果指向的是/除home/assets/image.jpg以外的其他页面,这是错误的 如何让图像解析到根/assets/目录,而不是指向除home/assets/以外的其他页面,SilverStripe提供了一些方法。HtmlEditor字段有一个可供点击的链接 您可以通过以下方式使用此方法: 1。创建扩展配置。 /mysit

我已从模板中删除了base_标记。这样做的一个副作用是,主页以外的页面上的图像会中断

HTMLEditorField::saveInto()
方法在图像上强制使用相对url,结果指向的是
/除home/assets/image.jpg以外的其他页面,这是错误的

如何让图像解析到根
/assets/
目录,而不是指向除home/assets/
以外的其他页面,SilverStripe提供了一些方法。HtmlEditor字段有一个可供点击的链接

您可以通过以下方式使用此方法:

1。创建扩展配置。

/mysite/_config/config.yml

2。在HTMLEditorFieldExtension类中创建一个新类。

/mysite/code/HTMLEditorFieldExtension.php


HtmlEditorField:
  extensions:
    - HTMLEditorFieldExtension
<?php
class HTMLEditorFieldExtension extends DataExtension
{
    // This method name must be the same as the extension hook
    public function processImage($image, $img) {

        // Get the image src attribute
        $src = $img->getAttribute('src');

        // Concatenate  a leading slash
        $img->setAttribute('src', '/' . $src);
    }
}