Jump to:

5514 Posts in 1733 Topics by 1219 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Adding custom content to the backend

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 2343 Views
  • danzzz
    Avatar
    Community Member
    175 Posts

    Adding custom content to the backend Link to this post

    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

  • edk
    Avatar
    Community Member
    39 Posts

    Re: Adding custom content to the backend Link to this post

    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

  • Willr
    Avatar
    Forum Moderator
    5489 Posts

    Re: Adding custom content to the backend Link to this post

    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.

  • danzzz
    Avatar
    Community Member
    175 Posts

    Re: Adding custom content to the backend Link to this post

    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

  • Willr
    Avatar
    Forum Moderator
    5489 Posts

    Re: Adding custom content to the backend Link to this post

    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.

  • CHD
    Avatar
    Community Member
    218 Posts

    Re: Adding custom content to the backend Link to this post

    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?

  • CHD
    Avatar
    Community Member
    218 Posts

    Re: Adding custom content to the backend Link to this post

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

    final code:

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

    2343 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.