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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

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   1177 Views

Avatar
ImacSS

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:

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!

Avatar
Willr

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.

Avatar
ImacSS

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.