Jump to:

22975 Posts in 11620 Topics by 2826 members

General Questions

SilverStripe Forums » General Questions » SS 2.4: modifying generated markup "assets" path

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 216 Views
  • ImacSS
    Avatar
    Community Member
    35 Posts

    SS 2.4: modifying generated markup "assets" path Link to this post

    Have an SS 2.4 site deployed. Client is running it out of <DOMAIN>/corporate/.

    Also, using the static exporter, as they did not want to have the CMS directly connected to their production site.

    All of the images that were added via the CMS, have "src" attributes that begin with "assets/...".

    I would like to know if it's possible (without using a global search & replace on the static output directory) to get the CMS to render these as:

    src="/corporate/assets/..."

    Looked at a solution online which suggested adding an onBeforeWrite() method to the Page class, like so...

    protected function onBeforeWrite() {
    parent::onBeforeWrite();
       $this->Content = str_replace(' src="assets/', ' src="/corporate/assets/', $this->Content);
    }

    However, this did not seem to have any effect when I re-ran the static exporter.

    Has anyone come up with a solution to this type of problem before?

    Thanks for any suggestions!

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: SS 2.4: modifying generated markup "assets" path Link to this post

    Your best bet is to run a post task after the static publisher has run to rewrite the static html. Or potentially, symlink assets/ to corporate/assets on the file system so you don't need to muck around with rewriting html files.

  • ImacSS
    Avatar
    Community Member
    35 Posts

    Re: SS 2.4: modifying generated markup "assets" path Link to this post

    Thanks Willr - that's ultimately what I wound up doing.

    Setup a "Search and Replace" custom script, which gets run at the very end of the static exporter batch script I created.

    Guessing that I could have done something with the overriding the File and Image objects' onAfterWrite method to accomplish the same, but figured this would be easier in the long run.

    216 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.