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.

General Questions

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

how to make a relation to pages in custom order?


5 Posts   290 Views


28 May 2013 at 4:29am (Last edited: 28 May 2013 4:30am), Community Member, 3 Posts

I have got several "Project"-Pages and want to show some of them in a custom order on my "Home"-Page.

Therefore I use the SortableGridField-Module in combination with the GridFieldConfig_RelationEditor:


public static $has_many = array(
'Highlights' => 'Project'

function getCMSFields()
$fields = parent::getCMSFields();
$conf->addComponent(new GridFieldSortableRows('HighlightSortOrder'));
$gridField = new GridField('Highlights', 'Highlight Projects', $this->Highlights(), $conf);
$fields->addFieldToTab("Root.Main", $gridField);

return $fields;


public static $db = array(

public static $default_sort = 'HighlightSortOrder';

It seems to work sometimes, but just after using the preview-Button in the admin-area.
There is also the problem, that all "Project"-Pages which are linked as Highlights, are now Subpages of the "Homepage" in the Sitetree.

Have you got an idea how to fix these problems or is there a better approach?



28 May 2013 at 1:10pm Community Member, 254 Posts

Hi ian-wig
try putting the reverse relationship on the project class

public static $db = array(
public static $has_one = array('Home' => 'HomeClass');

public static $default_sort = 'HighlightSortOrder';


28 May 2013 at 5:57pm (Last edited: 28 May 2013 6:27pm), Community Member, 3 Posts

Hi Bambii7,

thank you very much, that fixes the subpage-problem.

Unfortunately the template still doesn't show up the Highlights on the Homepage (even when I flushed):

<% loop $Highlights %>
<% end_loop %>

They appear when I click on Preview from the administration, but as soon as I log off, they disappear again.

Have you got an idea?


29 May 2013 at 3:19pm Community Member, 254 Posts

Hmmm have you checked the permissions on the ProjectClass? Perhaps they are set to be visible only to logged in users?


30 May 2013 at 6:55am Community Member, 3 Posts

Thanks again, but there are no special permissions used.

I figured out, that the Project always shows up in the Highlights, when the Project-Page is published after the relation was made in the GridField of the HomePage. The database relation between Home and Project (Home-Id) is only set in the Project-Table and not in the Project_Live-Table, which causes that strange behaviour, I guess.
I hope you undestand what the problem is ;)

Any solutions for publishing the grid-relation-change directly to Project-Table and Project_Live-Table?