Jump to:

3445 Posts in 1031 Topics by 872 members

Template Questions

SilverStripe Forums » Template Questions » Adding dynamic content (module?) while in the editor

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

Page: 1
Go to End
Author Topic: 999 Views
  • Jeff Vogt
    Avatar
    Community Member
    1 Post

    Adding dynamic content (module?) while in the editor Link to this post

    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
    Avatar
    Community Member
    181 Posts

    Re: Adding dynamic content (module?) while in the editor Link to this post

    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

    999 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.