Jump to:

23375 Posts in 18175 Topics by 2866 members

General Questions

SilverStripe Forums » General Questions » HTMLText Area & Adding Tab in Admin Manage Area

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

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

Page: 1
Go to End
Author Topic: 2584 Views
  • ckd
    Avatar
    Community Member
    18 Posts

    HTMLText Area & Adding Tab in Admin Manage Area Link to this post

    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?

  • Willr
    Avatar
    Forum Moderator
    5489 Posts

    Re: HTMLText Area & Adding Tab in Admin Manage Area Link to this post

    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)

  • ckd
    Avatar
    Community Member
    18 Posts

    Re: HTMLText Area & Adding Tab in Admin Manage Area Link to this post

    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 -->

  • banal
    Avatar
    Community Member
    901 Posts

    Re: HTMLText Area & Adding Tab in Admin Manage Area Link to this post

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

    new HtmlEditorField ("AboutContent", "About" )

  • ckd
    Avatar
    Community Member
    18 Posts

    Re: HTMLText Area & Adding Tab in Admin Manage Area Link to this post

    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.

    2584 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.