We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3749
    • 24,544 Posts
    As I said, xPDO will never get JSON data unless there is JSON data in the MODX database.

    It sounds like you're creating your own API. Are you asking how to get TV values and return them in JSON format from your API?

    This would be one way:

    Put a snippet tag on a page with an empty template:

    [[!GetTvs]]


    Then create a snippet called GetTvs with this code:

    /* GetTvs snippet */
    $tvIds = array(12,22,31); // Id's of the TVs you want to get
    $resourceId = 8; // ID or resource you want the TV values fromf
    
    $data = array(0;
    
    foreach ($tvs as $tvId) {
        $tv = $modx->getObject('modTemplateVar', $tvId);
        if ($tv) {
            $tvValue = $tv->renderOutput($resourceId);
            $tvName = $tv->get('name');
            $data[$tvName] = $tvValue;
        } else {
            /* TV not found -- handle error */
        }
    }
    
    $data = $modx->toJSON($data);
    
    echo $data;



      Did I help you? Buy me a beer
      Get my Book: MODX:The Official Guide
      MODX info for everyone: http://bobsguides.com/modx.html
      My MODX Extras
      Bob's Guides is now hosted at A2 MODX Hosting