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.

General Questions /

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

How to change Content before saving?


Reply


2 Posts   1416 Views

Avatar
dab

Community Member, 50 Posts

8 March 2009 at 9:00am

Im want to make post editor for Page Content (for good typography, like set up right dashes and quotes), i may call it every time i render page, but better and quicker solution is change Content before saving. So how i may do it?
Thank you.

Avatar
Willr

Forum Moderator, 5513 Posts

8 March 2009 at 11:53am

You can define a onBeforeWrite function on your page type. Eg if you want to edit the page content before you write to the database you would need to add this to your mysite/code/Page.php in the Page class

function onBeforeWrite() {
// do something
parent::onBeforeWrite();
}

For more information see http://doc.silverstripe.com/doku.php?id=datamodel#onbeforewrite