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.

Template Questions /

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

Re-use html-rendering / template

Go to End

11 Posts   3050 Views


Community Member, 51 Posts

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 provides with user controls that im looking for ( Html.RenderPartial("mycontrol", somedata) )


Community Member, 271 Posts

29 October 2010 at 3:57pm

Edited: 29/10/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 %>
<% end_control %>

See this thread on the Google Group channel:


Community Member, 51 Posts

31 October 2010 at 8:39pm

Edited: 31/10/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"));
<% control Pages %>
    $Title - ({$Link})
<% end_control %>

and used in the view like this:


But I actually like the other solution better - since its a bit cleaner.
Solution 2

Model describes a rendering for one object:
public function MyView(){
        return $this->renderWith(array('PageRendering'));

in view:
<% control GetAllPages %>
<% end_control %>

$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 !!

Go to Top