Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

General Questions /

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

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

SS 2.4: modifying generated markup "assets" path

Go to End

3 Posts   697 Views


Community Member, 35 Posts

15 May 2013 at 5:43am

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:


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

protected function 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!


Forum Moderator, 5523 Posts

15 May 2013 at 7:58pm

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.


Community Member, 35 Posts

20 May 2013 at 10:37am

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.