3217 Posts in 853 Topics by 812 members
| Go to End | ||
| Author | Topic: | 1767 Views |
-
Re: Re-use html-rendering / template

28 October 2010 at 10:46pm
ok - allow me to enter the sandbox and then get back to you.
main goal is:
1. never write the same markup twice. A list of MyObjects should always look the same, so no need to duplicate the markup.
2. being able to display same data twice without breaking goal number 1.Actually its the exact same functionality that asp.net provides with user controls that im looking for ( Html.RenderPartial("mycontrol", somedata) )
-
Re: Re-use html-rendering / template

29 October 2010 at 3:57pm Last edited: 29 October 2010 3:58pm
You can use function forTemplate() on a DataObject to specify a template for the DataObject.
Another way is to add a custom methods to you DataObjects and use renderwith to assign a template to the view
function MyView(){
return $this->renderWith('MyViewTemplate');
}In your template:
<% control MyDOSet %>
$MyView
<% end_control %>See this thread on the Google Group channel:
http://groups.google.com/group/silverstripe-dev/browse_thread/thread/0b0f299adb8177fd
-
Re: Re-use html-rendering / template

31 October 2010 at 8:39pm Last edited: 31 October 2010 8:50pm
Hi Martijn
Thank you so much for your reply! This was really helpful!
I actually managed to get another solution going, where I render the complete list of objects in one control and not the one object at a time. But this is only a matter of having the control-call in the include template or in the actual view.Solution 1:
public function ControllerGetAll() {
$page = $this->customise(array(
'Pages' => $this->GetAllPages()
));return $page->renderWith(array("PageList"));
}PageList.ss
<% control Pages %>
$Title - ({$Link})
<% end_control %>and used in the view like this:
$ControllerGetAll
But I actually like the other solution better - since its a bit cleaner.
Solution 2Model describes a rendering for one object:
public function MyView(){
return $this->renderWith(array('PageRendering'));
}in view:
<% control GetAllPages %>
$MyView
<% end_control %>PageRendering.ss
$Title - ({$Link})
//the control-blocks are moved to the "main-view" instead of inside the included rendering
The cool thing about solution 1 is that it can be used as a REST-ful ajax-call-include since it will give you the complete list rendering on www.yourdom.com/controller/ControllerGetAll !!
| 1767 Views | ||
| Go to Top |


