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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Set Default Value for HTMLEditor field + Rotate per day


Go to End


3 Posts   1385 Views

Avatar
Wezzlee

Community Member, 28 Posts

14 May 2013 at 6:30am

Hi,

I am working on a homepage template where a default value should be set when HTMLEditor field X is empty or when a day is passed and the HTMLEditor field X is not filled out with a new value.

I want to update the homepage every day with a daily menu. But it might occur that I forget to set the menu and because the daily menu changes every day I want to replace the menu with the opening times of the restaurant.

I am no php specialist so any help with this is appreciated. What do I need to alter to achieve this?

<?php
class HomePage extends Page {

static $db = array(
'Sidetext' => 'HTMLText'
);

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

return $fields;
}
}
class HomePage_Controller extends Page_Controller {
}

Thank you in advance,

Wesley

Avatar
Bambii7

Community Member, 254 Posts

15 May 2013 at 11:56am

Hi Wezzlee,
this might be a challenging requirement.

There is a Object called DailyTask you can extend to add daily tasks to. But this will also require that you set up a cron task to execute all daily tasks.

The other way, which ain't so elegant is to have an onBeforePublish method on your model. Which will check each time the page is loaded if the text has updated.

Those are two places to start looking.

Avatar
Wezzlee

Community Member, 28 Posts

16 May 2013 at 6:42am

Thank you Bambii7.

I will do some investigation with this information.

Wesley