Jump to:

23370 Posts in 18160 Topics by 2864 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: 3646 Views
  • Big Bang Creative
    Avatar
    Community Member
    92 Posts

    Multiple editable regions Link to this post

    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

  • erwanpia
    Avatar
    Community Member
    63 Posts

    Re: Multiple editable regions Link to this post

    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>

  • Big Bang Creative
    Avatar
    Community Member
    92 Posts

    Re: Multiple editable regions Link to this post

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

  • Big Bang Creative
    Avatar
    Community Member
    92 Posts

    Re: Multiple editable regions Link to this post

    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?

  • Big Bang Creative
    Avatar
    Community Member
    92 Posts

    Re: Multiple editable regions Link to this post

    Still have not got this to work. Please help.

  • Willr
    Avatar
    Forum Moderator
    5489 Posts

    Re: Multiple editable regions Link to this post

    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.

  • Big Bang Creative
    Avatar
    Community Member
    92 Posts

    Re: Multiple editable regions Link to this post

    Ahhh that did not work either.

  • Willr
    Avatar
    Forum Moderator
    5489 Posts

    Re: Multiple editable regions Link to this post

    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.

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