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, Ed, biapar, Willr, Ingo, swaiba

Customize my content with styled boxes

Go to End

6 Posts   1422 Views


Community Member, 141 Posts

15 July 2010 at 8:14pm

Hi all.
I just started using CMS and I am not that familiar on how to customize them. So, now I'd like to know how to get some "flexible" content in SS.
A quick example of what I mean by that.
Lets say I want several (styled) DIVs in my content (like that for example:
My first idea was to create a new page with 10 (in this case and example above) new fields. 5 for the photos and 5 for the text. But that is extremely inflexible, because I can't add more or less items/divs. I am stuck at 5!

It is pretty awful trying that just with the content editor :) Especially if the divs start getting more complex and you want to add some JS animations to it (hide text, hover images, slide out ...).

I hope you get what I want to achieve :)

How do you create pages like that? Do you have a dozen pages, all for just one content page? Do you write the code directly into the HTML editor?

You see, I don't have a clue what to do :)


Forum Moderator, 1899 Posts

19 July 2010 at 1:50am

I would create a new Page type PageXYZ (so code/PageXYZ.php and templates/Layout/ and then each of these as a templates/Includes/ and then edit the to <% include MyStyledBoxXYZ %>.

Or maybe you could look at doing something similar with Widgets and instead of being relegated to the "side bar" you could use them in the main area and then you could control them point and click style in the CMS.

Generally I use the page content for the stuff at the top of the page and then everything else is in the template and normally controlled (behaviour and content) from Dataobjects that are managed by ModelAdmin.

Not saying either of these are the best, but hope it helps...



Community Member, 141 Posts

19 July 2010 at 6:21pm

Barry, thanks for your answer.
Sorry, but I can't follow your first idea. Does it has any different to a "normal" page type?

Can you suggest a widget for my content?
I've read some sentences about the DataobjectManager. I think I have to read more about it.

I had some insight into another CMS yesterday. There I was able to create new fields and add the same fields as often as I need them. Maybe something like that is possibly in SS?

Thanks and bey


Forum Moderator, 1899 Posts

19 July 2010 at 10:52pm

I'd recomend you read through...



Forum Moderator, 1391 Posts

19 July 2010 at 11:39pm

Your first idea, adding a fixed couple of fields to the page, is indeed a bit inflexible. What you could do (aside from using widgets) is define a has_many relationship on your page. Suppose you created some DataObject class for styled boxes - lets call it 'StyledBox'.

So now in your Page class, you do:

static $has_many = array(
	'MyStyledBoxes' => 'StyledBox'

Your StyledBox class might look something like this:

class StyledBox extends DataObject{

	static $db = array(
		'Title' => 'Varchar()',

	static $has_many = array(
		'MyPage' => 'Page'


Now you can add as many StyledBox objects to the page as you wish. For the backend, in your Page's getCMSFields() function you would define a ComplexTableField for that purpose - or a DataObjectManager if you so wish.

In your page template you do something like:

<% control MyStyledBoxes %>
<% end_control %>

I agree with swaiba that I would create a new pagetype for this. Hope this helps some more,

Cheers, Martine


Community Member, 141 Posts

20 August 2010 at 4:15am

Edited: 20/08/2010 4:17am

Hi Martine.
Sounds like it is what I need :) Two questions …

1. What do you mean by 'Now you can add as many StyledBox objects to the page as you wish'?
2. The ComplexTableField-thing is something I can't get my head wrapper around it. The doc-page is too techy for me :(

Hope you can help. Thanks a lot!