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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

HTMLText Area & Adding Tab in Admin Manage Area


Go to End


5 Posts   3386 Views

Avatar
ckd

Community Member, 18 Posts

6 July 2009 at 2:37pm

I am having a great deal of trouble in adding some HTMLText areas on my pages. Have read the tutorials and viewed the related Forum Topics, however, it still does not work with respect to no Tab appearing in the Admin Area. Any help would be greatly appreciated. The code I am using in mysite/code/Page.php is:

<?php

class Page extends SiteTree {
	
	static $db = array(
	'AboutContent' => 'HTMLText'
	);
	
	static $has_one = array(
	);
	
}

class Page_Controller extends ContentController {
	
	public function init() {
		parent::init();

		// Note: you should use SS template require tags inside your templates
		// instead of putting Requirements calls here.  However these are
		// included so that our older themes still work
		Requirements::themedCSS("layout"); 
		Requirements::themedCSS("typography"); 
		Requirements::themedCSS("form");
		
	}
	
	/**
	 * Site search form 
	 */ 
	function SearchForm() {
		$searchText = isset($_REQUEST['Search']) ? $_REQUEST['Search'] : 'Search';
		$fields = new FieldSet(
	      	new TextField("Search", "", $searchText)
	  	);
		$actions = new FieldSet(
	      	new FormAction('results', 'Search')
	  	);

	  	return new SearchForm($this, "SearchForm", $fields, $actions);
	}
	
	/**
	 * Process and render search results
	 */
	function results($data, $form){
	  	$data = array(
	     	'Results' => $form->getResults(),
	     	'Query' => $form->getSearchQuery(),
	      	'Title' => 'Search Results'
	  	);

	  	return $this->customise($data)->renderWith(array('Page_results', 'Page'));
	}

	/**
	 * Address Details
	 */
	function getCMSFields(){
    $fields = parent::getCMSFields();
    $fields->addFieldToTab('Root.Content.About', new HtmlEditorField ( $name = "AboutContent", $title = "About" ), 'Content' );
    return $fields;
    }

}	

?>

The code I am using in templates\Page.ss is:

<div id="about"><!-- about -->
$AboutContent
</div><!-- /about -->

I have run /db/build?flush=1 and tried many other variations of the code based on information from the forums and tutorials but having no joy. Any ideas on what the issue could be?

Avatar
Willr

Forum Moderator, 5523 Posts

6 July 2009 at 3:07pm

Your function getCMSFields() is in the wrong class. It needs to be in the extends Page {} bit (referred to as the model) rather then the extends Page_Controller {} class where it is currently (referred to as the controller)

Avatar
ckd

Community Member, 18 Posts

6 July 2009 at 3:30pm

Thank you for your help. The tab has appeared, think I am almost there! However, for some reason when I click on it, it is not editable, just a blank white area with no editable regions. Is there any other code that I may have neglected to add?

My Page.php code now looks like this:

<?php

class Page extends SiteTree {
	
	static $db = array(
	'AboutContent' => 'HTMLText'
	);
	
	static $has_one = array(
	);
	
	function getCMSFields(){
    $fields = parent::getCMSFields();
    $fields->addFieldToTab('Root.Content.About', new HtmlEditorField ( $name = "AboutContent", $title = "About" ), 'Content' );
    return $fields;
    }
    
}

class Page_Controller extends ContentController {
	
	public function init() {
		parent::init();

		// Note: you should use SS template require tags inside your templates
		// instead of putting Requirements calls here.  However these are
		// included so that our older themes still work
		Requirements::themedCSS("layout"); 
		Requirements::themedCSS("typography"); 
		Requirements::themedCSS("form");
		
	}
	
	/**
	 * Site search form 
	 */ 
	function SearchForm() {
		$searchText = isset($_REQUEST['Search']) ? $_REQUEST['Search'] : 'Search';
		$fields = new FieldSet(
	      	new TextField("Search", "", $searchText)
	  	);
		$actions = new FieldSet(
	      	new FormAction('results', 'Search')
	  	);

	  	return new SearchForm($this, "SearchForm", $fields, $actions);
	}
	
	/**
	 * Process and render search results
	 */
	function results($data, $form){
	  	$data = array(
	     	'Results' => $form->getResults(),
	     	'Query' => $form->getSearchQuery(),
	      	'Title' => 'Search Results'
	  	);

	  	return $this->customise($data)->renderWith(array('Page_results', 'Page'));
	}

}	

?>

and Page.ss is:

<div id="about"><!-- about -->
$AboutContent
</div><!-- /about -->

Avatar
bummzack

Community Member, 904 Posts

6 July 2009 at 6:32pm

Your constructor call for the HtmlEditorField is wrong.
It should look like this:

new HtmlEditorField ("AboutContent", "About" )

Avatar
ckd

Community Member, 18 Posts

6 July 2009 at 7:55pm

I changed the contructor call code as you recommended, rebuilt the db but still no change. I did notice that after rebuilding, an extra 'Page not found' appears above 'Home' at the top of the Site Content & Structure menu tree in the admin area. This appears every time I rebuild the db for some reason.