Quote from: sottwell at Oct 31, 2014, 06:25 AMJust be aware that it will be a lot more processing-intensive, and thus slower, than a simple snippet, like the CopyYears snippet, which will display the current year or a range of years, like '2000-2014'
$now = date("Y");
$startYear = $modx->getOption('startYear', $scriptProperties, $now);
$spacer = $modx->getOption('spacer', $scriptProperties, '-');
$years = ($now > $startYear) ? $startYear.$spacer.$now : $now;
return $years;
have a snippet 'loop'
$loops = $modx->getOption('loops',$scriptProperties,10);
$tpl = $modx->getOption('tpl',$scriptProperties,'');
for ($i=0; $i < $loops; $i++){
$p['idx'] = $i;
$output[] = $modx->getChunk($tpl,$p);
}
$output = implode('<br />',$output);
return $output;
another snippet 'nowdate':
return strftime('%Y-%m-%d %H:%M:%S');
I call it:
[[!loop? &loops=`10000` &tpl=`nowdate`]]
having in the nowdate-chunk:
[[!+nowdate:default=`now`:strtotime:date=`%Y-%m-%d %H:%M:%S`]]
first output: 2014-10-31 07:09:09
last output: 2014-10-31 07:09:20
having in the nowdate-chunk:
first output: 2014-10-31 07:21:34
last output: 2014-10-31 07:21:50
So, I don't know why,
but with the output-filter-version, I have allways about 10secs between the first and last output.
With the snippet-version, I have allways about 15secs for 10000 loops.
When I replace getChunk in the snippet with strftime directly:
$loops = $modx->getOption('loops',$scriptProperties,10);
$tpl = $modx->getOption('tpl',$scriptProperties,'');
for ($i=0; $i < $loops; $i++){
$p['idx'] = $i;
$output[] = strftime('%Y-%m-%d %H:%M:%S');
}
$output = implode('<br />',$output);
return $output;
there is no difference between the first and last output, so much less than one second without the getChunk - parsing - process.
[ed. note: Bruno17 last edited this post 9 years, 5 months ago.]