We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 21258
    • 14 Posts
    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.
      • 4172
      • 5,888 Posts
      nice!

      You could also use phx for date-formatting:

      example:
      [+startDate:date=`%d.`+]-[+endDate:date=`%d.%m.%Y`+]


      or create a new snippet, which you call like this in your ditto-tpl:

      [[formateventdate? &startDate=`[+startDate+]` &endDate=`[+endDate+]`]]
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 21258
        • 14 Posts
        Quote from: Bruno17 at Aug 13, 2009, 01:32 AM

        or create a new snippet, which you call like this in your ditto-tpl

        Haha... I never realised you could call snippets from chunks, that would have been way easier. Thanks!