Jump to:

5450 Posts in 1672 Topics by 1197 members

Customising the CMS

SilverStripe Forums » Customising the CMS » New CMS Fields Help

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 2717 Views
  • Tonupbandit
    Avatar
    Community Member
    7 Posts

    New CMS Fields Help Link to this post

    Hi all. New to Silverstripe, so far I think it's a great tool, having lots of fun learning. Have been trying to add new fields to the CMS and am having some trouble. Followed the tutorials on adding Date and Author fields, from there figured out how to add two new text fields and pull them into the CMS:

    class HomePage extends Page {
    static $db = array(
    'Recent Work' => 'Text',
        'New Work' => 'Text'
    );
    static $has_one = array(
    );

    function getCMSFields() {
    $fields = parent::getCMSFields();

    $fields->addFieldToTab('Root.Content.Main', new TextField('Recent Work'));
    $fields->addFieldToTab('Root.Content.Main', new TextField('New Work'));

    return $fields;
    }
    }

    The problem I'm having is that I can't get the fields to display text-wrapping. Right now, they both show up under $Content, which is where I want them, but they only display a single line. I'd like them to function similarly to the $Content field - e.g. expanding as needed when data dictates. Also, the default font that is applied to content in these new fields appears different to that applied to data put into the $Content field. I know fonts will be handled on the site by my CSS, but it seems odd that new fields don't correspond with the existing format. Might be useful if the tutorial addressed this type of customization as opposed to just the single line examples. Thanks in advance for any help and or insights.

  • Tobbe
    Avatar
    Community Member
    25 Posts

    Re: New CMS Fields Help Link to this post

    Hi!

    The input fields are one line, as you have choosen the TextField as the type (the new TextField("XXX", "XXX");

    Check this wiki page: http://doc.silverstripe.com/doku.php?id=form-field-types

    Here you can see that the "TextareaField" is a multiline text input and if you like it as the $Content, you should use "HtmlEditorField". Please note, that if you choose to use the HtmlEditorField, you should also change the $db array from "Text" to "HTMLText". See: http://doc.silverstripe.com/doku.php?id=htmleditorfield

    Hope this helps,
    /Tobbe

  • Tonupbandit
    Avatar
    Community Member
    7 Posts

    Re: New CMS Fields Help Link to this post

    Thanks much Tobbe! Worked out exactly as I hoped.

    2717 Views
Page: 1
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.