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

Problems adding new content field


Go to End


3 Posts   1582 Views

Avatar
whitmoa

Community Member, 2 Posts

14 October 2016 at 11:11am

Edited: 14/10/2016 11:16am

Hi, all.

I'm new to SilverStripe (v3.4.1) and I'm struggling to add a new HTML field to the database and the CMS. I've watched a number of UncleCheese lessons, followed a couple of tutorials and read a number of posts. I thought I had it figured out but it's simply not working for me. I'm trying to add another HTML text field to the content tab of the page editor. It's to allow me to separate out banner content, so I'd ideally like it to appear immediately above the 'Content' window (although I haven't got as far as working out the display order!).

After I add the relevant code to Page.php and flush by appending /db/build?flush=1 to my URL, the page edit area in the CMS is completely blank. Just the CMS menu on the left and nothing else. This is the top of my Page.php file...

<?php
class Page extends SiteTree {

	private static $db = array(
		'Banner' => 'HTMLText'
	);

	private static $has_one = array(
	);

	public function getCMSFields() {
		$fields = parent::getCMSFields();
		$fields->addFieldToTab("Root.Content", new HTMLEditorField('Banner','Banner'));
		return $fields;
	}

}

I've also tried "Root.Main" and "Root.Content.Main" to no avail. What am I missing? Please help!

Adam

Avatar
ZarockNZ

Community Member, 17 Posts

18 October 2016 at 11:27am

Hi,

The code you wrote looks fine. The correct tab to add the field to is "Root.Main". Also you can pass "Content" as the third parameter to make the field appear before it. I.e...

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

The blank white screen must mean there is some sort of error. Have you tried looking in / tailing the apache or nginx error log? Perhaps take a look at this thread about the "blank screen" issue: https://www.silverstripe.org/community/forums/general-questions/show/10495

Avatar
Vix

Community Member, 60 Posts

20 October 2016 at 6:12pm

Edited: 20/10/2016 6:14pm

Hello, not sure if it was a typo or not but instead of:

appending /db/build?flush=1

You need to append /dev/build?flush=1 (or flush=all)

Also make sure you have:

Director::set_environment_type("dev");

In your config file to make sure all error messages are being shown.