Jump to:

22998 Posts in 11620 Topics by 2827 members

General Questions

SilverStripe Forums » General Questions » Populate default data at page creation

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
Go to End
Author Topic: 1682 Views
  • BigChris
    Avatar
    Community Member
    63 Posts

    Populate default data at page creation Link to this post

    Hello,

    is it possible to have SilverStripe populate a HTMLText field with default data at page creation?

    By this I mean when you are in the Admin section and create a new page and choose a page type, it creates the page but also comes with some default data populated. This is so the data can then be changed.

    I had a look at the recipe http://doc.silverstripe.org/doku.php?id=recipes:populatedefaults but not sure how to go about having this work for page creation only.

    Regards
    Chris

  • Chris Hope
    Avatar
    Community Member
    18 Posts

    Re: Populate default data at page creation Link to this post

    @silverluke Thanks for your answer. I had already worked out how to populate default stuff for the admin but was wondering how to do a dynamic default.

    @BigChris I can't offer any more than silverluke other than to add I've been doing this myself to get some default information into the HTML for a particular page type. You can of course put HTML in the string as well, run it over multiple lines etc e.g.:

    static $defaults = array(
          'Content' => "<h1>Heading</h1>
                <p>Content here</p>
                <h2>Some other sort of heading</h2>
                <p>Some other sort of content</p>"
    );

    Obviously your defaults would be more applicable to the page type than what I've put there

  • BigChris
    Avatar
    Community Member
    63 Posts

    Re: Populate default data at page creation Link to this post

    Fantastic!

    Thank you for your help, it did the job.

    Cheers
    Chris

  • PHP Engine
    Avatar
    Community Member
    2 Posts

    Re: Populate default data at page creation Link to this post

    Hi,

    Thanks for that - I just thought I'd make an addendum...

    I used the above detailed process, and it worked great, only thing was I wanted to pre-populate the Title field in the metadata tab (for the Blog module). So I tried:
    static $defaults = array(
    'Title' => "My Company | Blog Post | "
    );
    which didn't work...
    Its because this field is referred to in code as MetaTitle and not Title, even though the label next to the field is Title. Anyways, I found this simply by using firebug, I think the id of the field is the correct name to use in the array key here, but you'll see it clearly.

    anyway, the correct answer is here:

    static $defaults = array(
    'MetaTitle' => "My Company | Blog Post | "
    );

    and this was in BlogEntry.php

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