Jump to:

23007 Posts in 11866 Topics by 2828 members

General Questions

SilverStripe Forums » General Questions » how to make a relation to pages in custom order?

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

Page: 1
Go to End
Author Topic: 234 Views
  • ian-wig
    Avatar
    Community Member
    3 Posts

    how to make a relation to pages in custom order? Link to this post

    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:

    Home-Class

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

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

    return $fields;
    }

    Project-Class

    public static $db = array(
    'HighlightSortOrder'=>'Int'
    );

    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?

    Thanks!

  • Bambii7
    Avatar
    Community Member
    254 Posts

    Re: how to make a relation to pages in custom order? Link to this post

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

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

    public static $default_sort = 'HighlightSortOrder';

  • ian-wig
    Avatar
    Community Member
    3 Posts

    Re: how to make a relation to pages in custom order? Link to this post

    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?

  • Bambii7
    Avatar
    Community Member
    254 Posts

    Re: how to make a relation to pages in custom order? Link to this post

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

  • ian-wig
    Avatar
    Community Member
    3 Posts

    Re: how to make a relation to pages in custom order? Link to this post

    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?

    234 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.