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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Customising the CMS /

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

Advice on best approach to custom data objects


Go to End


3 Posts   1318 Views

Avatar
rp55139

Community Member, 3 Posts

8 September 2014 at 8:39pm

Hi,

I'm new to Silverstripe and am trying various approaches to the following use case and was hoping I'd be able to get some pointers from seasoned developers!

The homepage to my site has three horizontal tiles in the middle of the page - each tile is an image or a video with a title, some copy and a link.

I can use a HTML field to allow the user to edit the HTML direct, but this will allow them to corrupt the DOM.
I can use approx. five custom fields for each of the three tiles, but this will clutter the admin UI (I could use three ToggleCompositeField objects to help mitigate).

Is it possible to manage a list of custom "Tile" DataObjects and have three select list fields in my homepage template to pull from the list of DataObjects?

I've looked into widgets and various other threads - if there's a best practice it would be great to have your feedback.

Thanks,

Richard

Avatar
kinglozzer

Community Member, 187 Posts

9 September 2014 at 4:13am

Edited: 09/09/2014 4:13am

Hi Richard,

I think the method you choose is really down to personal preference. Personally, I would use a DataObject (or multiple DataObject classes) and a GridField (you can remove the "Add new" button if there are 3 already added).

If the tiles are very similar (i.e. image/video is the only thing different, the rest of the fields are always the same) then I'd use one DataObject and show/hide the fields conditionally.

If they're quite different, I'd use multiple DataObject classes (probably inheriting from a "Tile" class which contains any fields that do not change) and use ajshort's gridfieldextension module which adds a dropdown for picking which class to add: https://github.com/ajshort/silverstripe-gridfieldextensions/blob/master/docs/en/index.md#multi-class-adding.

Hope this helps,
Loz

Avatar
rp55139

Community Member, 3 Posts

9 September 2014 at 8:39am

Thanks for getting back to me Loz, much appreciated.

I'll take a look into the gridfieldextension module and see how I get on.

Richard