MODx template variable image make downloadable

107 views Asked by At

I work in MODx Evolution and created a template variable which is an image. I want this image to be downloadable by my website visitors. Is that possible, how?

This link gives valuable info... but the issue with my requirement is the MODx template variable and the fact that I do not have a specific path to specify. ... similar Stackoverflow question answered

1

There are 1 answers

0
Sean Kimball On BEST ANSWER

What is happening is that your TV output type is set to "image" - Modx will output an image tag in that situation and not just the path. You can change the output type to default so that only the path is output, then you can pass that to your download/push scripts. OR leave the TV type as is and write another snippet to retrieve the TV value, which will be the path & filename. Docs here

Something like:

/call snippet
[[!getMyTVvvalue? &id=`[[*id]]`]]

// snippet 
$resource = $modx->getObject('modResource', $id);
return $resource->getTVValue('my_image_tv');

// might be handier to output it to a placeholder
$my_path = $resource->getTVValue('my_image_tv');
$modx->toPlaceholder('my_image_path', $my_path);

// output in your page
[[+my_image_path]]

Though it would be easiest to just change your output type.