Hi,
I would like to create a page that automatically downloads a pdf-file as soon as I select this page via a link.
More precisely:
I would like to have a link to a page with a template in the footer-menu, which only offers a PDF for download instead of page content (preferably without actually calling up the this page).
@isaactopo:
I know about the download attribute, but unfortunately that’s not what I would like to do.
I would like to create a page (+ template + blueprint) where the editor in the backend sees only a field for the file-upload. If this page is called up by a visitor (click on the link in the [Footer] menu), the dialog box of the browser which offering the download should open instead of the page content.
I also know the way with pure PHP
I just thought that Kirby might already have a built-in-function/method that provides this, but as always, I’m missing what I’m looking for
@texnixe
I would like to have it based on a temple and not with a route. A route refers more to a page, right?
As already described above, the editor should simply select the template (e.g. with the name “Download File”) when he creates a page, insert the file and save it. If the page is listed, it is displayed in the menu and when a website visitor click it, no page appears, but the download is offered…
Then I’ll probably do it exactly as you instructed. I’m not quite sure yet whether forwarding with go() isn’t the more user-friendly way, since the PDF may then be displayed directl if the browser supports it.
You could also create a model for the download template, and overwrite the url function to point to the file instead. This way you don’t even need a template.
site/models/download.php
<?php
use Kirby\Cms\Page;
class DownloadPage extends Page {
public function url($options = null): string {
if($file = $this->file('myfile')) {
return $file->url();
}
return parent::url($options);
}
}