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.

Template Questions /

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

Adding dynamic content (module?) while in the editor

Go to End

2 Posts   1297 Views

Jeff Vogt

Community Member, 1 Post

17 April 2009 at 6:44pm

Say I have a function in mysite/code/Page.php:

helloWorld() {
return 'hello world';

If I'm editing a template, it's as easy as typing $helloWorld wherever I want the output of my function. What I want to do is be able to do this from SilverStripe Admin when I (or a user) is editing a page.

How would I do this without tearing SS apart? Is this not proper separation of MVC?

Ben Gribaudo

Community Member, 181 Posts

18 April 2009 at 1:19am

Hi Jeff,

If I understand correctly, you want to be able to type "$HelloWorld" in the TinyMCE editor and then have that string replaced with the value of HelloWorld() when the page is rendered. Is that correct?

When SS renders a page for display, it calls the Content() method on the page's class. You can override this method, adding the behavior you desire.

Example (in your page's class):

	public function Content() {
		return str_replace('$HelloWorld', $this->helloWorld(), $this->Content);

Hope this helps,