Jump to:

520 Posts in 248 Topics by 263 members

Content Editor Discussions

SilverStripe Forums » Content Editor Discussions » calculated field in content

Forum for content editors and CMS users.

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

Page: 1
Go to End
Author Topic: 874 Views
  • RuthEd
    Avatar
    Community Member
    3 Posts

    calculated field in content Link to this post

    Hi

    I'd like the person editing the page content in TinyMce to be able to insert a calculated field, eg the next 4th Friday. I have a php function that calculates the next nth specified day, but the user needs to be able to specify the week and the day. ie something like 'The next meeting is on nextdate(4,6)'.

    Is this possible to do? preferably easily!

    Thanks

  • Devlin
    Avatar
    Community Member
    215 Posts

    Re: calculated field in content Link to this post

    /**
    * replace string in Content
    * [ Untested ]
    */
    public function Content() {
       $this->Content = str_replace( "nextdate(4,6)", $this->nextdate(4,6), $this->Content );
       return $this->Content;
    }

    /**
    * parse next date
    * [ Untested ]
    */
    public function nextdate($var1,$var2) {
       return "whenever";
    }

  • RuthEd
    Avatar
    Community Member
    3 Posts

    Re: calculated field in content Link to this post

    Thanks. The numbers 4 and 6 in nextdate(4,6) are parameters and may be any numbers (the 6 could go up to 12). I don't know how to pick these out.

  • Devlin
    Avatar
    Community Member
    215 Posts

    Re: calculated field in content Link to this post

    http://php.net/manual/en/function.preg-replace.php

    /**
    * replace string in Content
    * [ Untested ]
    */
    public function Content() {
       //$this->Content = "The next meeting is on nextdate(4,6)";
       $this->Content = preg_replace(
             "#nextdate\((.+?),(.+?)\)#is",
             $this->nextdate("\\1","\\2"),
             $this->Content);
       return $this->Content;
    }

    /**
    * parse next date
    * [ Untested ]
    */
    public function nextdate($var1,$var2) {
       return "whenever";
    }

  • RuthEd
    Avatar
    Community Member
    3 Posts

    Re: calculated field in content Link to this post

    Thanks for your help. I've decided that maybe it's not such a good idea to parse the content. Perhaps I'll try adding a page type with a couple of fields for the user to choose the parameters and put the call to the function in the template.

  • Devlin
    Avatar
    Community Member
    215 Posts

    Re: calculated field in content Link to this post

    You can also replace values with TinyMCE and the template/snippets plug in.

    http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/template

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