Ok I have found a way to sort the result output in the template.
As it turns out it's actually easy.
I have added a function to my custom SiteConfig:
public function footerCol3data(){
return $this->owner->FooterCol3Pages(null, "`SiteConfig_FooterCol3Pages`.`ID`");
}
concerning the following relation
function extraStatics() {
return array(
'many_many' => array(
"FooterCol3Pages" => "SiteTree"
),
);
}
and added to the CMS by:
$fields->addFieldToTab("Root.Menus", new TreeMultiselectField($name = "FooterCol3Pages", $title = "Sider i footer kolonne 3", "SiteTree"));
In the template i can now loop the data like this:
<% control SiteConfig.footerCol3data %>
<li class="{$ClassName}"><a href="$Link"><span>$MenuTitle</span> id: $ID</a></li>
<% end_control %>
When TreeMultiselectField is used in the backend, it posts a list of selected page id's, that is then added to the relation table.
Each selected pages id is written in the order it was clicked in the CMS. That allows us to order the pages by the relation id = giving us the pages in the order they were added.
NOTE: If editing the selected pages in the TreeMultiselectField, notice that the sort order might not work as expected, this is because the relation table is only updated if the ID of the selected page is not allready in the relation table. To set the sort order, deselect all pages in the TreeMultiselectField, press save. Reselect the pages in the desired order, save and it should be ok.
Took some time to figure this out, hope it helps someone :o)