Jump to:

3393 Posts in 976 Topics by 852 members

Template Questions

SilverStripe Forums » Template Questions » use template control within content

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

Page: 1
Go to End
Author Topic: 965 Views
  • Banana
    Avatar
    Community Member
    18 Posts

    use template control within content Link to this post

    the idea is the following:

    put into the content ( which is edited with the tiny ) a control tag.
    eg. <% control Page(url) %>$Content<% end_control %>

    if you add the Control function in the Page_Controller like this:

    public function Content(){
    $MySSViewer = new SSViewer_FromString($this->Content);
    return $this->renderWith($MySSViewer);
    }

    it looks like it would to the trick. But is does not !
    It only replaces the variables eg. $Title or $Content, but does not execute the Controller function(s).
    eg. if there is a news listing at the target page, the listing is not shown, since the listing code is not executed.

    is there a way to achive this ?

    do you need more information ?

    thx for any help

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: use template control within content Link to this post

    When you are controlling in the template (such as <% control Page(url) %>) you only get the data record and *not* the controller. In this case your content method needs to be in the Page class rather than Page_Controller.

  • Banana
    Avatar
    Community Member
    18 Posts

    Re: use template control within content Link to this post

    hmm so first we have the Content function in the controller.
    this one renders the content with renderWith.

    Within the content it finds the $Content and now finds the Content() function in the Page class.

    until this step it all works fine.

    but now I have a loop. since it always finds the Content() funktion it will use this over and over again.

    .......thinking....

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: use template control within content Link to this post

    You need to make a slight change to your code

    $MySSViewer = new SSViewer_FromString($this->Content);

    SS will resolve $this->Content to that function so you may want to play around with getting the db object directly

    $MySSViewer = new SSViewer_FromString($this->dbObject('Content'));

  • Banana
    Avatar
    Community Member
    18 Posts

    Re: use template control within content Link to this post

    I already solved this by not using the Content function.

    the special code which will be placed into the content field looks like this now (fater being replaced):

    <% control Page(url) %>$SpecialContent<% end_control %>

    this way the loop is prevented.

    if the target page uses its own template and within there are calls to functions within the controller class, it will "fail".
    Sinc I want the "complete" result and not only the result if the content db field.
    If I copy the special functions from the page_controller into the Page class it works. I get the complete result of the targetet page with its template. But this way could not be the solution, since the functions will be on two places...

    965 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.