3212 Posts in 847 Topics by 809 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 884 Views |
-
Adding dynamic content (module?) while in the editor

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?
-
Re: Adding dynamic content (module?) while in the editor

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,
Ben
| 884 Views | ||
|
Page:
1
|
Go to Top |


