Custom page list block with buttons for forced file download
Permalink
How to approach creating a custom page list block (I know this part) with the option for users to click on bottom page titles and start direct file download?
I can only think of using page descriptions and putting the link there. But first, to obtain the link itself, the client would need to create such a link by creating file download block, copying the link and then incorporating it in the description. It's a bit of an overkill so I'm looking for a more elegant approach.
Any ideas?
I can only think of using page descriptions and putting the link there. But first, to obtain the link itself, the client would need to create such a link by creating file download block, copying the link and then incorporating it in the description. It's a bit of an overkill so I'm looking for a more elegant approach.
Any ideas?
You could add a File Attribute to the page and then in your custom template or custom block output the download link for that file.
Nice idea. I've done that and now, I can output the download link like this: $fileDLLink = $page->getAttribute('dl_link', 'display');
However, this outputs the complete link (A element) which shows the file name in File Manager. Is there a way for me to retrieve only the DL link path so I can use it whatever I like (ie. create my own A element)?
Thanks!
However, this outputs the complete link (A element) which shows the file name in File Manager. Is there a way for me to retrieve only the DL link path so I can use it whatever I like (ie. create my own A element)?
Thanks!
You can use the getDownloadURL instead. So do
I can't rememve if getAttribute gives you back a file object or a file ID, if it gives back a file object you just need to change $fileDLID to $f and remove the second line there.
$fileDLID = $page->getAttribute('dl_link'); $f = File::getByID($fileDLID); $fileDLLink = $f->getDownloadURL();
I can't rememve if getAttribute gives you back a file object or a file ID, if it gives back a file object you just need to change $fileDLID to $f and remove the second line there.
It returns a very large array? I noticed in this same block (page_list) that page thumbnail is retrieved in the same fashion (ie. $page->getAttribute('thumbnail'); and is used in image creation like this:
$img = Core::make('html/image', array($thumbnail));
===================
I tried as you suggested:
$f = $page->getAttribute('dl_link');
// $f = File::getById($fileID);
$fileDLLink = $f->getDownloadURL();
but I'm getting this error: "Call to a member function getDownloadURL() on a non-object"
$img = Core::make('html/image', array($thumbnail));
===================
I tried as you suggested:
$f = $page->getAttribute('dl_link');
// $f = File::getById($fileID);
$fileDLLink = $f->getDownloadURL();
but I'm getting this error: "Call to a member function getDownloadURL() on a non-object"
If you are getting "Call to a member function getDownloadURL() on a non-object" then that attribute is probably not set for the page. You can change your code to be like this to check for that
$f = $page->getAttribute('dl_link'); if(is_object($f)){ $fileDLLink = $f->getDownloadURL(); }
Yep, that was the case exactly! I've set this attribute for only one out of 3 pages for testing purposes and I also forgot I was in a loop there so probably an exception is thrown in iterations where the attribute isn't set.
Thank you very much for your help, this now works as expected!!
Thank you very much for your help, this now works as expected!!