Jump to:

23461 Posts in 18908 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Set Default Value for HTMLEditor field + Rotate per day

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: 395 Views
  • Wezzlee
    Avatar
    Community Member
    28 Posts

    Set Default Value for HTMLEditor field + Rotate per day Link to this post

    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

  • Bambii7
    Avatar
    Community Member
    254 Posts

    Re: Set Default Value for HTMLEditor field + Rotate per day Link to this post

    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.

  • Wezzlee
    Avatar
    Community Member
    28 Posts

    Re: Set Default Value for HTMLEditor field + Rotate per day Link to this post

    Thank you Bambii7.

    I will do some investigation with this information.

    Wesley

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