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.

Content Editor Discussions

Forum for content editors and CMS users.

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

calculated field in content


Reply

6 Posts   887 Views

Avatar
RuthEd

23 July 2010 at 8:57pm Community Member, 3 Posts

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

Avatar
Devlin

24 July 2010 at 1:36am (Last edited: 24 July 2010 1:39am), Community Member, 215 Posts

/**
* 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";
}

Avatar
RuthEd

24 July 2010 at 3:06am Community Member, 3 Posts

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.

Avatar
Devlin

24 July 2010 at 3:29am (Last edited: 24 July 2010 3:32am), Community Member, 215 Posts

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

/**
* 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";
}

Avatar
RuthEd

24 July 2010 at 4:06pm Community Member, 3 Posts

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.

Avatar
Devlin

24 July 2010 at 9:09pm (Last edited: 24 July 2010 9:10pm), Community Member, 215 Posts

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

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