# Download link for each subpage

**URL:** <https://forum.getkirby.com/t/download-link-for-each-subpage/4565>\
**Category:** Questions\
**Tags:** v2\
**Created:** [June 29, 2016, 4:23pm UTC](https://forum.getkirby.com/t/download-link-for-each-subpage/4565 "2016-06-29T16:23:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rbnschlz](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/rbnschlz/32/2481_2.png) [@rbnschlz](https://forum.getkirby.com/u/rbnschlz)\
**Post date:** [June 29, 2016, 4:23pm UTC](https://forum.getkirby.com/t/download-link-for-each-subpage/4565/1 "2016-06-29T16:23:20Z")

</div>

Hi everyone,  
I am currently trying to set a route to force the download of a pdf on many different subpages.  
Each subpage/project will have its own pdf. In the template I’d like to link to “index/projectname/download”.

How do I set the route for this?  
So far I’ve got the following:

```
c::set('routes', array(
  array(
    'pattern' => 'index/(:any)/download',
    'action' => function() {

      page()
        ->files()
        ->filterBy('extension', 'pdf')
        ->first()
        ->download();
    }
  )
));

```

I believe I need to tell kirby to fetch the current page’s pdf, but I have no idea how to.

Thanks!

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [June 29, 2016, 5:08pm UTC](https://forum.getkirby.com/t/download-link-for-each-subpage/4565/2 "2016-06-29T17:08:38Z")

</div>

You can get the project page like this:

```auto
c::set('routes', array(
  array(
    'pattern' => 'index/(:any)/download',
    'action' => function($uri) {
      $page = page($uri);
      $page
        ->files()
        ->filterBy('extension', 'pdf')
        ->first()
        ->download();
    }
  )
));

```

---

<div class="post-metadata">

**Author:** ![lukasbestle](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/lukasbestle/32/11437_2.png) [@lukasbestle](https://forum.getkirby.com/u/lukasbestle)\
**Post date:** [June 29, 2016, 5:16pm UTC](https://forum.getkirby.com/t/download-link-for-each-subpage/4565/3 "2016-06-29T17:16:43Z")

</div>

The example above works if the page is on the top level of the site. If your projects are all subpages of a specific page, you can get the page like this:

```auto
$page = page('projects/' . $uri);

```

---

<div class="post-metadata">

**Author:** ![rbnschlz](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/rbnschlz/32/2481_2.png) [@rbnschlz](https://forum.getkirby.com/u/rbnschlz)\
**Post date:** [June 29, 2016, 5:21pm UTC](https://forum.getkirby.com/t/download-link-for-each-subpage/4565/4 "2016-06-29T17:21:38Z")

</div>

thanks guys, works like a charm!

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [February 6, 2025, 4:57pm UTC](https://forum.getkirby.com/t/download-link-for-each-subpage/4565/5 "2025-02-06T16:57:39Z")

</div>

Archived on February 6, 2025, 4:57pm UTC


