2016-04-28 16 views
2

テンプレートto allow for the use of SVG icon spritesからbase_tagを削除しました。これの副作用は、ホームページ以外のページの画像が壊れることです。Silverstripe wysiwyg画像がbase_tagなしで動作しない

HTMLEditorField::saveInto()の方法では、イメージに相対URLが強制され、最終的には/some-page-other-than-home/assets/image.jpgを指していますが間違っています。

​​を指すのではなく、ルート/assets/ディレクトリに解決するイメージを取得するにはどうすればよいですか。

答えて

1

SilverStripeはいくつかの方法でextension hooksを提供します。 HTMLEditorFieldには'processImage' hookがあります。

次に、このメソッドにフックすることができます

1.あなたの拡張機能の設定を作成します。

/mysite/_config/Config.yml

HtmlEditorField: 
    extensions: 
    - HTMLEditorFieldExtension 

2. HTMLEditorFieldExtensionクラスを作成します。

/mysite/code/HTMLEditorFieldExtension.php

<?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); 
    } 
} 

3.ファイル名を指定して実行DEV /ビルド。

これは、SilverStripeが新しい拡張子を見つけることができるようにする必要があります。この後、画像にはスラッシュがありません。

関連する問題