21285 Posts in 5732 Topics by 2602 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 2094 Views |
-
HTMLText Area & Adding Tab in Admin Manage Area

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?
-
Re: HTMLText Area & Adding Tab in Admin Manage Area

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)
-
Re: HTMLText Area & Adding Tab in Admin Manage Area

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 --> -
Re: HTMLText Area & Adding Tab in Admin Manage Area

6 July 2009 at 6:32pm
Your constructor call for the HtmlEditorField is wrong.
It should look like this:new HtmlEditorField ("AboutContent", "About" )
-
Re: HTMLText Area & Adding Tab in Admin Manage Area

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.
| 2094 Views | ||
|
Page:
1
|
Go to Top |



