Jump to:

22997 Posts in 11620 Topics by 2827 members

General Questions

SilverStripe Forums » General Questions » Multiple editable regions

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 2 3
Go to End
Author Topic: 3512 Views
  • Big Bang Creative
    Avatar
    Community Member
    92 Posts

    Re: Multiple editable regions Link to this post

    Ah great it works a treat. This has been holding back a few projects!!

    Thanks for the help

  • Valorinbattle
    Avatar
    Community Member
    95 Posts

    Re: Multiple editable regions Link to this post

    I followed these instructions and was able to get the field to appear in the CMS, but cannot get anything to show up on the actual site from this "testing" field.

    Also, how can I reorder this field so it shows up above the original Content field?

  • Big Bang Creative
    Avatar
    Community Member
    92 Posts

    Re: Multiple editable regions Link to this post

    How can I get the new field to only show for certain pages (page types)?

  • Big Bang Creative
    Avatar
    Community Member
    92 Posts

    Re: Multiple editable regions Link to this post

    Did you remember to add in $testing into your template where you want the content?

    I would also like to know about it appearing above the content field as I have a banner section. I tried adding the new field above: $fields = parent::getCMSFields(); but that did brought an error.

  • Big Bang Creative
    Avatar
    Community Member
    92 Posts

    Re: Multiple editable regions Link to this post

    1. Can I get new fields to only show for certain pages (page types)?
    2. How can I position the new fields above the Content fields?

  • Valorinbattle
    Avatar
    Community Member
    95 Posts

    Re: Multiple editable regions Link to this post

    BigBang, I was able to add the $testing field and get it to show only on the HomePage page type and above my other content fields.
    Here is what my code from Homepage.ss - near the bottom in <div id="flashbanner">

    <body class="typography">
    <div id="header">
       <div id="searchbox">$SearchForm</div>
       <div id="menu">
          <!-- [if IE6]><div id="IE6"><![endif]-->
    <ul id="Menu1">
       <% control Menu(1) %>
          <% if Children %>
             <li class="top $LinkingMode"><a href="$Link" class="top_link" title="View more info about $Title"><span>$MenuTitle</span><!--[if gte IE 7]><!--></a><!--<![endif]-->
                <!--[if lte IE 6]><table><tr><td><![endif]-->
                <ul class="sub1">
                   <% control Children %>
                      <li><a href="$Link" title="View more about $Title" class="fly $LinkingMode">$MenuTitle</a></li>
                   <% end_control %>
                </ul>
             <!--[if lte IE 6]></td></tr></table></a><![endif]-->
             </li>
          <% else %>   
             <li class="top $LinkingMode"><a href="$Link" class="top_link" title="View more info about $Title"><span>$MenuTitle</span></a></li>
          <% end_if %>
       <% end_control %>
    </ul>
    <!-- [if IE6]></div><![endif]-->
       </div>   
    </div>
    <div id="pageHome">
       <div id="contactus">
          <a href="http://www.lovesdoor.org/contactus/">contact us</a><span id="whitefont">&nbsp;&nbsp;|&nbsp;</span>
          <a href="http://www.lovesdoor.org/aboutus/">about us</a>
       </div>
       <div id="flashbanner">$testing</div>
       <div id="contenttop">&nbsp;</div>
       <div id="content">$Layout</div>
       <div id="contentbottom">&nbsp;</div>   
    </div>    
    <div id="pagebottom"></div>
    <div id="foot"><% include Footer %></div>
    </body>

  • Valorinbattle
    Avatar
    Community Member
    95 Posts

    Re: Multiple editable regions Link to this post

    Alas though I have my own problem too.

    I was able to the editable content field 'testing' by using this code in Page.php:

    static $db = array(
       'testing' => 'HTMLText'
    );
    function getCMSFields() {
    $fields = parent::getCMSFields();
    $fields->addFieldToTab('Root.Content.Main', new HTMLEditorField('testing', 'testing'));
    return $fields;
    }

    But when I tried to add another editable content field, ie 'testing2' I got a weird error. Here was my code:

    static $db = array(
       'testing' => 'HTMLText',
    'testing2' => 'HTMLText'
    );
    function getCMSFields() {
    $fields = parent::getCMSFields();
    $fields->addFieldToTab('Root.Content.Main', new HTMLEditorField('testing', 'testing'));
    $fields->addFieldToTab('Root.Content.Main', new HTMLEditorField('testing2', 'testing2'));
    return $fields;
    }

    I flushed the DB and the field successfully added to the CMS. I am able to have any text typed in that box successfully display on the webpage. But if I try to add an image or a flash element in that box, I get this error in the "uploads" box in the top right of the CMS:

    Fatal error: Class name must be a valid object or a string in C:\wamp\www\OrphanHope\sapphire\core\model\DataObject.php on line 1543

    I googled the error, not finding anything in these forums, and it says it's a PHP problem that required a patch. I find that hard to believe, since I was able to use the exact same code to add the 'testing' content field.

    ~ James

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: Multiple editable regions Link to this post

    @Big Bang:

    1. If you want fields to only be on certain page types then you ned to add those fields to those page types model class rather than the base Page class. So if you wanted it only on your HomePage then in HomePage.php add the fields to the getCMSFields() function and also to the $db array.

    2. To control where a field goes add a third argument to the addFieldToTab call. The following will add the field above 'Content':

    $fields->addFieldTotTab("Root.Content.Main", new TextField("SomeText"), "Content");

    @Valorin:

    Can you confirm that adding images works when you do it in the original content editor (the one that is on all pages by default)?

    Are you able to load the 'Files & images' section? What are the file types you are trying to add?

    3512 Views
Page: 1 2 3
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.