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

Multiple editable regions


Go to End
Reply


17 Posts   4333 Views

Avatar
Big Bang Creative

Community Member, 92 Posts

4 February 2009 at 12:22am

Edited: 04/02/2009 12:23am

I am trying to do add multiple editable regions to a template. I found this thread (http://silverstripe.org/archive/show/104369) explaining how to do it but it is in the archive and I did not understand it.

Does anyone have an example mysite/code/Page.php file so I can see how it works. I tried adding the code myself (with basically no PHP knowledge) and it did not work.

Any help would be great.

Ash

Avatar
erwanpia

Community Member, 63 Posts

4 February 2009 at 12:56am

Edited: 04/02/2009 12:58am

Hi bigbang

my humble opinion is that silverstripe is not for php beginners but if you are good at copy and paste try this (replace in mysite/page.php) , that's some code I used for multiple paragraph layout (3columns). As I say to my object experienced php developper who works with me on silverstripe, don't forget to flush your database after this (tutorial 1 )!!

<?php

class Page extends SiteTree {
	static $db = array(
	  'TitreContenu2' => 'Text',
	  'TitreLogo' => 'Text',
	  'ColonneGauche'=> 'HTMLText',
	  'ColonneMilieu'=> 'HTMLText',
	  'ColonneDroite'=> 'HTMLText',
	  'ParagrapheBas'=> 'HTMLText',	  	  	  
	);
	static $has_one = array( 'Photo1' => 'Image'   );	
	
   function getCMSFields() {
   $fields = parent::getCMSFields();
   //renommer les champs
  // $fields->renameField("Content", "SousTitre");
   
   //champs additionnels
    $fields->addFieldToTab('Root.Content.Main', new TextField('TitreContenu2', 'Titre de Contenu (2e ligne)'), "MenuTitle");
   $fields->addFieldToTab('Root.Content.Entetes', new TextField('TitreLogo', 'Titre de Logo'));
   $fields->addFieldToTab('Root.Content.Entetes', new ImageField('Photo1', 'Photo1'));
 $fields->addFieldToTab('Root.Content.Paragraphes', new HTMLEditorField('ColonneGauche', 'Colonne de gauche'));
 $fields->addFieldToTab('Root.Content.Paragraphes', new HTMLEditorField('ColonneMilieu', 'Colonne du milieu'));
  $fields->addFieldToTab('Root.Content.Paragraphes', new HTMLEditorField('ColonneDroite', 'Colonne de droite'));
   $fields->addFieldToTab('Root.Content.Paragraphes', new HTMLEditorField('ParagrapheBas', 'Paragraphe de pied de page'));
	return $fields;
   }
}

class Page_Controller extends ContentController {
	function init() {
		parent::init();
		
		Requirements::themedCSS("layout");
		Requirements::themedCSS("typography");
		Requirements::themedCSS("form");
	}
}

?>

here you 'll find the associated 3 column layout with tests in case some columns are not visible


<table ><tr>
	<td  valign="top" width="<% if ColonneDroite %>260<% else %>390<% end_if %>" ><% if ColonneGauche %>		
<div id="ColonneGauche"	>$ColonneGauche</div>
<% end_if %></td>

<% if ColonneMilieu %>		
<td style="border-left:1px solid #0056B5;"  width="<% if ColonneDroite %>260<% else %>390<% end_if %>" valign="top">
<div id="ColonneMilieu"	>$ColonneMilieu</div></td>
<% end_if %>

</tr></table>

 

<% if ParagrapheBas %>
<div id="ParagrapheBas"> $ParagrapheBas</div>
<% end_if %>
</td>

<% if ColonneDroite %>
<td valign="top" style="border-left:1px solid #0056B5;" width="245"  >
<div id="ColonneDroite">$ColonneDroite</div>
</td>
<% end_if %>
</tr></table>

Avatar
Big Bang Creative

Community Member, 92 Posts

4 February 2009 at 3:24am

Cheers for the help, that looks a lot more clear! I will give this a try ASAP!

Avatar
Big Bang Creative

Community Member, 92 Posts

4 February 2009 at 3:58am

Edited: 04/02/2009 3:59am

I have followed this and it did not work.

My page.php file looks like this:

<?php

class Page extends SiteTree {
static $db = array(
'testing'=> 'HTMLText'
);
static $has_one = array(
);
}

function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Content.Main', new HTMLEditorField('testing', 'testing'));

return $fields;
}

class Page_Controller extends ContentController {
function init() {
parent::init();

Requirements::themedCSS("layout");
Requirements::themedCSS("typography");
Requirements::themedCSS("form");
}
}

?>

I added $testing into the template and then flushed the database. The flush showed it added to the database (the green text).

I presumed this would add in another text field in the CMS but it didn't. Any ideas? have I missed something?

Avatar
Big Bang Creative

Community Member, 92 Posts

17 February 2009 at 3:47am

Still have not got this to work. Please help.

Avatar
Willr

Forum Moderator, 5521 Posts

17 February 2009 at 5:25pm

That looks correct. So that doesn't add a field to your Content tab underneath the content box?

Try $fields->addFieldToTab('Root.Content.Test', new HTMLEditorField('testing', 'testing')); and see if that creates a 'Test' tab in the content editor.

Avatar
Big Bang Creative

Community Member, 92 Posts

17 February 2009 at 11:29pm

Ahhh that did not work either.

Avatar
Willr

Forum Moderator, 5521 Posts

18 February 2009 at 9:19am

Ah i just used your code and it indeed doesn't work. This is because of a } that shouldnt be there (line 9) the getcmsfields function needs to be inside that brace.

Go to Top