I have spent quite a bit of time trying to figure out how to access the template variables from within an extender and since I couldn’t find anything on this in the forum I thought I’d post something in case it is useful to others.
My situation was that I needed to access the TV’s from each page, work with output and then put it in a placeholder.
The following extender worked for me and retrieves 2 TVs from the page (startdate and enddate), formats them, concatenates the results and returns the result to the eventdate placeholder.
$placeholders['eventdate'] = array(array("eventdate","*"),"exampleFunction");
if (!function_exists("exampleFunction")) {
function exampleFunction($resource) {
global $modx;
$startDate = $modx->getTemplateVarOutput('startdate',$resource['id']);
$startDate = date("jS", $startDate['startdate']);
$endDate = $modx->getTemplateVarOutput('enddate',$resource['id']);
$endDate = date("jS M Y", $endDate['enddate']);
$eventDate = "$startDate-$endDate";
return $eventDate;
}
}
The reason I needed to do this was because I was using unixtime for the date TVs and needed to format them before Ditto output the results.
The Ditto call used was:
[!Ditto? &startID=`8` &filter=`startdate,@EVAL return strtotime("now");,3` &extenders=`dateFormat` &tpl=`eventsummary` &showInMenuOnly=`1` &showarch=`0` &truncLen=`100` &truncSplit=`0`!]
The extender is named dateFormat.extender.inc.php and the filter returns only events where the start date is in the future.