Adding Image/File download attribute code

Permalink 1 user found helpful
Hi

I have set up a site using the real-estate addon which uses the composer, our client wants to add a property PDF download to the listings page. I have added a Image/File attribute and I can upload a PDF when adding a property but I have no idea how to add the code to the page to make the download work. Just want a Download PDF link on the page. Looking at real_estate_listing.php I guess I need to add
$file_download = $c->getAttribute('file_download'); in the <?php global section but not sure what to add to get the download to work.

anybody know how I can do this?

Thanks.

View Replies: View Best Answer
Steevb replied on at Permalink Reply
Steevb
This might help:http://www.concrete5.org/community/forums/customizing_c5/any_idea_how_i_make_pdfs_open_as_a_page/#21035
oakleafg replied on at Permalink Reply
Thanks for the reply but not what I was meaning, wanting to know what code I need to add to a composer page to make a download link to a file upload.
ScottSandbakken replied on at Permalink Best Answer Reply
ScottSandbakken
You need to get the file object from the page attribute, then grab the current version and ask it for the download url.

$page = Page::getCurrentPage();
$f = $page->getAttribute('file_attribute_handle');
$fv = $f->getApprovedVersion();
$url = $fv->getDownloadURL();


Then just create the link.

<a href="<?php echo $url; ?>">Download Listing</a>
ScottSandbakken replied on at Permalink Reply
ScottSandbakken
You could also add a File block to your page type defaults and then add that block to Composer.
oakleafg replied on at Permalink Reply
That works perfectly. Thank you.