Link to PDF in content folder not working

I’ve been trying to link to a PDF document in one of my content folders. I have tried using the methods on the cheat sheet, but it is not returning the url.

<?php if($file = $page->file('oddbird-menu.pdf')): ?>
    <a href="<?php echo $file->url() ?>" type="button" class="btn btn-default btn-lg" target="_blank">
      Download PDF
    </a>
<?php endif ?>

Help!

That code is perfect. Does the file exist in the page’s folder and is the spelling of the filename correct? And what is the error message if any? Or just nothing?

That’s what is blowing my mind. It is in the folder and named correctly. When I view the page, the button doesn’t appear.

What happens if you just echo the url?

<?php echo $page->file('oddbird-menu.pdf')->url() ?>

[Edit] Maybe the page is just trying to fool you today …

1 Like

I think it is. I wonder if I messed up things when I created a single page scrolling site.

Ah, single page: then maybe instead of $page->file() you should use $data->file() or whatever variable you use for the sections of the page …

That worked! Thanks for the help. I’ve created other sites using Kirby, but it’s the first time I’ve attempted a single page.