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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Template Questions /

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

use template control within content


Go to End


5 Posts   1682 Views

Avatar
Banana

Community Member, 18 Posts

24 November 2010 at 3:08am

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

Avatar
Willr

Forum Moderator, 5523 Posts

24 November 2010 at 5:42pm

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.

Avatar
Banana

Community Member, 18 Posts

24 November 2010 at 9:45pm

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

Avatar
Willr

Forum Moderator, 5523 Posts

24 November 2010 at 10:31pm

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'));

Avatar
Banana

Community Member, 18 Posts

24 November 2010 at 10:53pm

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