Howto use output modifier to show and calculate page refresh time

I´ve got <meta http-equiv="Refresh" content="[[*page-refresh-time]]"> in my template head. User can set page refresh time if wanted. If time is empty this block not shown on page.
Trying to output page refresh time. This calculates value to minutes and works well:


<section class="container">
<p><small>Page is updated every <mark>[[*page-refresh-time:divide=`60`]] minutes!</mark></small></p>
<div class="progress2 progress-moved"><div class="progress-bar2"></div>

Now I want that it not show when tv is empty, shows result in seconds under value 60 and shows results in minutes to 60 and above values. It would be nice if minute result could be rounded in two decimals.


Modx 3.0.3+ Pico Css

You probably have to create a custom output modifier for this.

Take a look at this page in the MODX documentation:

Damn! I think it would be easy output modifier thing.
My skills are just not creating custom output modifier level. I think original output is good enough for my use.

But maybe some day…

This shouldn’t be too hard to implement.

Here is some code that maybe does what you need:

$seconds = (int) $input;
if (!$seconds) return '';
$minutes = (int) floor($seconds / 60);
$seconds = $seconds % 60;

$output = '';
if ($minutes){
    $minutes_plural = $minutes == 1 ? '' : 's';
    $output = "{$minutes} minute{$minutes_plural}";
if ($seconds){
    $seconds_plural = $seconds == 1 ? '' : 's';
    $output.= " {$seconds} second{$seconds_plural}";
return trim($output) . "!";

You ROCK! This outputs just like it should, more than expected, calculates and outputs minutes and seconds nicely! Thank you so very much! This is why I love Modx. With skills you can do anything without any hassle!

I know this is easily done with JavaScript, but I have minimal project (Pico css+Modx3) going on my webpages. That´s why wanted output modifier for this thing. So far pages running without any JavaScript, only html, css and php (plugin that gets random image from my Piwigo gallery to Modx).

Here´s my project (sorry only in finnish language):

This topic was automatically closed 2 days after discussion ended and a solution was marked. New replies are no longer allowed. You can open a new topic by clicking the link icon below the original post or solution and selecting “+ New Topic”.