Redirect page title to file

Hi, I have been struggling to find a way to have my page title redirect to open a PDF file in the browser.

What I have (obviously) been able to do is insert [file](file.pdf) into a default Grav themed page, and clicking on the link in the page, the browser opens the PDF.

Is there a way to do the same immediately from the page title? So that clicking on the page title doesn’t open the page, but directly the pdf?

I could use the redirect frontmatter, but then I can’t seem to reference a local file, but would have to upload the PDF to some other cloud provider and create a share link.

Thanks!

Which theme are you using and could you please indicate which part of your theme page contains what you refer to as “page title”? That term is open to different interpretations.

Thanks! I’m using the default Grav theme, Quark, without any modifications. The page title is the text that I put in the — title: ---- frontmatter.

Quick update: I have been able to achieve what I want with having the following frontmatter:

---
title: <page title>
redirect: 'http://localhost:8080/<path_to_pdf.pdf>'
---

(page still in development, so currently runs in localhost. I guess I’ll have to change it to the deployed url…)

I’m wondering whether there is a method though that is more elegant than hardcoding the URL into the page frontmatter.

Thanks!

Probably you will need make some changes in your twig template, for example, downloads.html.twig in this way:

<a href="{{ file.url }}" download>{{ page.title }}</a>

Your file.url may be your first file of page.media {{page.media.all|first}} if you have only one pdf per page. Otherwise you have to define this file in the blueprint of downloads page.

This is indicative. It might be interesting for you to take a look at Grav’s documentation on blueprints and media.

Surely someone on this forum will have a more specific idea and can help you much better.

ok, got it. Thanks a lot!