Hardcode Link to Download a File in File Manager

Permalink
If I want to hardcode a link to a page in my site I can use <a href="<?php getTheURL(71); ?>" with:

<?php
function getTheURL($url_id) {
$opg = Page::getById($url_id);
$url=Loader::helper('navigation');
$canonical=$url->getCollectionURL($opg);
$canonical=preg_replace("/index.php\?cID=1$/","",$canonical);
echo $canonical;
}
?>

Is there a similar piece of code if I want to hardcode a link to download a file in the File Manager?

 
tone72 replied on at Permalink Reply
For anyone else experiencing this issue, this is the solution I used:

I decided to use the Scrapbook function and created a new Scrapbook 'file' block with a unique name ('MyScrapbookName'). I wanted the file to download via a button so I created a Custom Template and applied this to the 'file' block in the Scrapbook.

You can create a Custom Template for block type 'File' by creating a folder called 'templates' in concrete > blocks > file > create the new templates folder here. I copied the existing view.php in the file folder and pasted it into my new template folder. I renamed it 'button.php' and added my button class to the code. The new template is now available as a Custom Template option for the 'file' block.

In my index.php file I used the following code that permits you to hardcode a Scrapbook item -

<?php
$block = Block::getByName('MyScrapbookName');
$block->display();
?>

It worked great. The client can't change the button when they are in edit mode for the page and the correct file downloads when the button is clicked.

Hope this helps someone else too!