21294 Posts in 5734 Topics by 2602 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1393 Views |
-
Populate default data at page creation

25 March 2010 at 12:06am
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 -
Re: Populate default data at page creation

25 March 2010 at 12:03pm
Hi there, the easiest way is to have your Page type declare the following:
static $defaults = array(
'Content' => 'This is the default content for the Content HTMLField'
};If you need some logic, or something more complicated, then you can use populateDefaults().
Either of these methods for defaults apply only to page creation.
Cheers,
- Luke. -
Re: Populate default data at page creation

25 March 2010 at 2:07pm
@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
-
Re: Populate default data at page creation

27 March 2010 at 10:07pm
Fantastic!
Thank you for your help, it did the job.
Cheers
Chris -
Re: Populate default data at page creation

5 April 2011 at 9:23pm
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
| 1393 Views | ||
|
Page:
1
|
Go to Top |



