Ah great it works a treat. This has been holding back a few projects!!
Thanks for the help
This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.
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.
Ah great it works a treat. This has been holding back a few projects!!
Thanks for the help
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?
How can I get the new field to only show for certain pages (page types)?
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.
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?
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"> | </span>
<a href="http://www.lovesdoor.org/aboutus/">about us</a>
</div>
<div id="flashbanner">$testing</div>
<div id="contenttop"> </div>
<div id="content">$Layout</div>
<div id="contentbottom"> </div>
</div>
<div id="pagebottom"></div>
<div id="foot"><% include Footer %></div>
</body>
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
@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?