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

Adding custom content to the backend


Go to End


7 Posts   4802 Views

Avatar
danzzz

Community Member, 175 Posts

10 March 2010 at 9:14am

hi there,

I want add custom content on some tabs in the backend. For example this way I can add a new field to a tab:

$fields->addFieldToTab('Root.Content.Main', new HTMLEditorField('Field', 'Field'));

But how can I add own content, for example just a string or the result of a function or a class?

If I want to call a own class there, is it enough to just put my class into /mysite/ direcotry? Will SS loads that automaticly?

thx
danzzz

Avatar
edk

Community Member, 39 Posts

10 March 2010 at 10:19am

Edited: 10/03/2010 10:20am

Hi Danzzz,

You could try adding a new LiteralField to that tab.

Example:
$fields->addFieldToTab('Root.Content.Main', new LiteralField('','<p>Hello World</p>'),"Content");

Check out the documentation too for other available fieldtypes and examples. http://doc.silverstripe.org/doku.php?id=form-field-types

-chango

Avatar
Willr

Forum Moderator, 5523 Posts

10 March 2010 at 4:41pm

If I want to call a own class there, is it enough to just put my class into /mysite/ direcotry? Will SS loads that automaticly?

Yes. SS picks up any files in any folder which has a _config.php file at the second level but will ignore a folder / not include classes if a '_manifest_exclude' file is present.

Avatar
danzzz

Community Member, 175 Posts

12 March 2010 at 1:05am

thx,

willr:

are there other methods to include or load own content to tabs than literalfield?

what I want to do is:

create a new tab.
in this tab I want show extern news articels grabbed from rss feeds.
the user can activate the news items which should shown on the frontpage.

thx for your input ...

daniel

Avatar
Willr

Forum Moderator, 5523 Posts

12 March 2010 at 11:19am

Well you can only insert subclasses of form fields in the backend tabs (since it is one big form). You could always make your own form field type which had whatever you wanted. Have alook at how LiteralField does it. The key function is Field() which returns the object to insert. So you could define that function in your own form field to render with a different template or some more hard core things.

Avatar
CHD

Community Member, 219 Posts

16 December 2010 at 2:59pm

hmmm i've tried this:

function getCMSFields() {
$fields = parent::getCMSFields();

$fields->addFieldToTab('Root.Content.Availability', new LiteralField('','<p>Hello World</p>'),"Content");

return $fields;
}

and the tab is just blank?

Avatar
CHD

Community Member, 219 Posts

16 December 2010 at 3:14pm

oooops, ignore that. i was messing around with the " & '!

final code:

$fields->addFieldToTab('Root.Content.Availability', new LiteralField("","<p>Hello World</p>"));