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.

General Questions /

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

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

[solved] Multiple related pages


Go to End


3 Posts   1293 Views

Avatar
theade

Community Member, 10 Posts

25 September 2012 at 5:20pm

Hey. I'm looking for a quick pointer. I want a carousel of images on the front page of a site that could contain X items - an image, text link and url for each item. I want the user to be able to customise how many items and add the content for each, from a tab on the front page.

So at the moment I have a hardwired amount of items in the HomePage class:

		$fields->addFieldToTab('Root.Content.Carousel', new TextField('TitleOne','1. Title'));
		$fields->addFieldToTab("Root.Content.Carousel", new TextField('HoverTextOne', '1. Hover Text'));
		$fields->addFieldToTab('Root.Content.Carousel', new TreeDropdownField("LinkOneID", "1. Link","SiteTree"));
		$fields->addFieldToTab("Root.Content.Carousel", new ImageField('ImageOne', '1. Carousel Image'));

		$fields->addFieldToTab('Root.Content.Carousel', new TextField('TitleTwo','2. Title'));
		$fields->addFieldToTab("Root.Content.Carousel", new TextField('HoverTextTwo', '2. Hover Text'));
		$fields->addFieldToTab('Root.Content.Carousel', new TreeDropdownField("LinkTwoID", "2. Link","SiteTree"));
		$fields->addFieldToTab("Root.Content.Carousel", new ImageField('ImageTwo', '2. Carousel Image'));

... etc

This works OK, but it's ugly and limiting. The ideal solution would be an "add another" button, and a remove button. But I've no idea where to start. Am I missing something fundamental like a nice module or something?

Thanks

Avatar
martimiz

Forum Moderator, 1391 Posts

25 September 2012 at 10:57pm

Hi theade,
What I would do is create a new DataObject class for the image, url and other properties, then use either a ComplexTableField or DataObjecManager (ss version 2.4) or a GridField (ss version 3.0) on your homepage to add/edit your image objects. This way you can dynamically add as many object as you like.

Avatar
theade

Community Member, 10 Posts

26 September 2012 at 11:50am

Spot on. Thanks for your help. Muchly appreciated.