Hi all,
So I have a MIGx table with some play showtimes for a local theater company. Let's say I have the table loaded with 5 separate showtimes:
Date:
2014-02-06
2014-02-07
2014-02-08
2014-02-09
2014-02-10
On the frontend I'd like to display some of this information as Play Title: Feb 6th-10th
Is there a way to pull just the dates from the first row and the last row of the MIGx table?
untested snippet, which should find the first and last Date and outputs the first and last item as placeholders.
<?php
$items = $modx->fromJson($modx->getOption('value',$scriptProperties,''));
$dateField = $modx->getOption('dateField',$scriptProperties,'date');
$firstPrefix = $modx->getOption('firstPrefix',$scriptProperties,'first.');
$lastPrefix = $modx->getOption('lastPrefix',$scriptProperties,'last.');
$events = array();
if (is_array($items)){
foreach ($items as $item){
$events[$item[$dateField]] = $item;
}
}
ksort($events);
reset($events);
$first = current($events);
$last = end($events);
$modx->toPlaceholders($first,$firstPrefix);
$modx->toPlaceholders($last,$lastPrefix);
[[getFirstLast? &value=`[[*yourMIGXtv]]`]]
[[+first.date]] - [[+last.date]]
I think you can use Jako's daterange-snippet of his daterange-TV - package to format the output of this placeholders:
https://github.com/Jako/DaterangeTV
[ed. note: Bruno17 last edited this post 12 years, 8 months ago.]