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.

Customising the CMS /

Adding custom content to the backend


Reply


7 Posts   2473 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. [url]http://doc.silverstripe.org/doku.php?id=form-field-types[/url]

-chango

Avatar
Willr

Forum Moderator, 5513 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, 5513 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, 218 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, 218 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>"));