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

Add HTML content between form fields in ModelAdmin


Go to End


3 Posts   1841 Views

Avatar
Jare

Community Member, 39 Posts

28 September 2015 at 8:44am

Hi,

I have been googling around for a while now, but somehow can't seem to find any answers even though this seems very simple problem. My goal is to add and edit some form fields in getCMSFields() method (no problem with that) and also to add some HTML content that comes from a template between some of the fields.

The template part is clear. I use something like this to get the HTML content from the template I want:

class MyDataObject extends DataObject
{
    public function getCMSFields()
    {
        $fields = parent::getCMSFields();
        $content = $this->renderWith('SomeTemplateForMyDataObject');
        //Insert $content to $fields here. How? Or is there a better way?
        return $fields;
    }
}

Thank you for your kind support! :)

Avatar
Feejin

Community Member, 4 Posts

2 October 2015 at 10:36pm

Is LiteralField what you're after? E.g.

$myContent = LiteralField::create('MyContent', $content);
$fields->insertAfter($myContent, 'NameOfFieldToInsertAfter');

Avatar
Jare

Community Member, 39 Posts

3 October 2015 at 1:45am

Thanks, that's the one! :) And the insertAfter() is nice too. So far I've only used addFieldToTab()'s third parameter to insert a new field between existing ones, and have thought that being a little counter-intuitive because that method inserts the new element _before_ the given element.