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   2413 Views

Avatar
danzzz

10 March 2010 at 9:14am Community Member, 175 Posts

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

10 March 2010 at 10:19am (Last edited: 10 March 2010 10:20am), Community Member, 39 Posts

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

10 March 2010 at 4:41pm Forum Moderator, 5511 Posts

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

12 March 2010 at 1:05am Community Member, 175 Posts

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

12 March 2010 at 11:19am Forum Moderator, 5511 Posts

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

16 December 2010 at 2:59pm Community Member, 218 Posts

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

16 December 2010 at 3:14pm Community Member, 218 Posts

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

final code:

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