I am using the DataObjectManager to manage some files per-page. Thus far I have done this:
<% control DownloadItems %>
<li><a href="$Attachment.URL">$Title</a></li>
<% end_control %>
Now what I need to do is create a function for this but I am stuck. I want to create the function so I can build one single url that contains these links that I will send to an external site for processing. I.e. the end result might be:
<li><a href="http://example.com/process.php?downloads=http://mysilverstripewebsite.com/assets/Uploads/file1.pdf+http://mysilverstripewebsite.com/assets/Uploads/file2.pdf+http://mysilverstripewebsite.com/assets/Uploads/file3.pdf>Download</a></li>
I have been trying to build this link on a per-page level in Page_Controller.php here's what I have so far:
function DownloadList()
{
$thisFiles = DataObject::get("DownloadItem", "PageID = 2"); // Pages at the root level only
$output = "";
return $thisFiles;
}
Two immediate problems. One, is that the '2' should be the id of the page they are on. Two, when I call $DownloadList in Page.ss it returns this:
<li onclick="location.href = this.getElementsByTagName('a')[0].href"><a href="">File1</a></li>
<li onclick="location.href = this.getElementsByTagName('a')[0].href"><a href="">File2</a></li>
I don't know where all that <li> code is coming from but it seems this very close. It's just missing the link to the file, and of course the ability for me to customize how the output is returned.
Please help!