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.

General Questions /

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

Multiple editable regions


Reply


17 Posts   3957 Views

Avatar
Big Bang Creative

Community Member, 92 Posts

19 February 2009 at 5:24am

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

Thanks for the help

Avatar
Valorinbattle

Community Member, 95 Posts

24 February 2009 at 12:41pm

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?

Avatar
Big Bang Creative

Community Member, 92 Posts

27 February 2009 at 5:03am

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

Avatar
Big Bang Creative

Community Member, 92 Posts

27 February 2009 at 5:06am

Edited: 27/02/2009 5:13am

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.

Avatar
Big Bang Creative

Community Member, 92 Posts

3 March 2009 at 12:47am

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?

Avatar
Valorinbattle

Community Member, 95 Posts

4 March 2009 at 8:03pm

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>

Avatar
Valorinbattle

Community Member, 95 Posts

4 March 2009 at 8:13pm

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

Avatar
Carbon Crayon

Community Member, 598 Posts

4 March 2009 at 11:54pm

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