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   922 Views

Avatar
RuthEd

Community Member, 3 Posts

23 July 2010 at 8:57pm

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

Community Member, 217 Posts

24 July 2010 at 1:36am

Edited: 24/07/2010 1:39am

/**
* 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

Community Member, 3 Posts

24 July 2010 at 3:06am

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

Community Member, 217 Posts

24 July 2010 at 3:29am

Edited: 24/07/2010 3:32am

[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

Community Member, 3 Posts

24 July 2010 at 4:06pm

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

Community Member, 217 Posts

24 July 2010 at 9:09pm

Edited: 24/07/2010 9:10pm

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

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