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

Add HR into tab in admin


Reply


4 Posts   1337 Views

Avatar
DeklinKelly

Community Member, 197 Posts

6 May 2009 at 6:57am

I have created a custom tab in the admin.

I would like to place a divider or <hr /> between sections.

Can this be done?

Attached Files
Avatar
Double-A-Ron

Community Member, 604 Posts

6 May 2009 at 10:40am

I'm not sure if this is the best way, but the HeaderField field type works well for me when I need to insert any custom HTML into the CMS forms.

In your case, in your getCMSFields function of the Page, you would add a HeaderField in the relevant position like so:

....
$fields->push( new TextField( 'Item1Link', 'Item 1 Link' ));
$fields->push( new HeaderField( '<hr />', '3', true ) );
$fields->push( new TextField( 'Item2Title', 'Item 2 Title' ));
....

The first argument is the HTML you want to insert. The second is the Header size (not relevant in this case), and the third is to tell the method to allow HTML in the first argument.

http://api.silverstripe.com/forms/fields-dataless/HeaderField.html

Cheers
Aaron

Avatar
Willr

Forum Moderator, 5513 Posts

6 May 2009 at 5:32pm

Rather then a header field - which is designed for Header elements (<h1>) a better one would be the LiteralField() which is designed to just output whatever you pass it.

Avatar
DeklinKelly

Community Member, 197 Posts

6 May 2009 at 11:19pm

Thank you.

I combined your answers to create this working code:

$fields->addFieldToTab("Root.Content.Item", new LiteralField('CustomCode1','<hr />'));