We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 33983 ☆ A M B ☆
    • 181 Posts
    I have created a TV with the input type File and output is set to default. I am using a plugin on the OnDocFormSave to get and save this value to custom database table. I want to get the complete processed file path but the api is only returning partial path. Note this is for groupeletters: https://github.com/jgulledge19/GroupEletters/

    Here is the code for the two methods I have tried:

    $attachments = $resource->getTVValue('eletterAttachment');
    // returns: about/image.jpg
                
    $tv = $modx->getObject('modTemplateVar', array('name'=>'eletterAttachment'));
    $attachments = $tv->renderOutput($resource->get('id'));
    // also returns: about/image.jpg
    


    Now when I call on the TV via the Content it does output the full path: assets/content/about/image.jpg. How do I get that assets/content part with the API?

    This question has been answered by jgulledge19. See the first response.

    • discuss.answer
      • 33983 ☆ A M B ☆
      • 181 Posts
      I got it to work here is the code:

       $tv = $modx->getObject('modTemplateVar', array('name'=>'eletterAttachment'));
       $tvValue = $tv->getValue($resource->get('id'));
       $source = $tv->getSource();
       $source->initialize();
       $path = $source->getBasePath();
       $attachments = array(str_replace(MODX_BASE_PATH, '', $path).'/'.ltrim($tvValue,'/'));