# Using permalink template varaibles on pages

**URL:** <https://talk.jekyllrb.com/t/using-permalink-template-varaibles-on-pages/1406>\
**Category:** Help\
**Created:** [January 26, 2018, 9:11am UTC](https://talk.jekyllrb.com/t/using-permalink-template-varaibles-on-pages/1406 "2018-01-26T09:11:28Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnlane](https://avatars.discourse-cdn.com/v4/letter/j/eb8c5e/32.png) [@johnlane](https://talk.jekyllrb.com/u/johnlane)\
**Post date:** [January 26, 2018, 9:11am UTC](https://talk.jekyllrb.com/t/using-permalink-template-varaibles-on-pages/1406/1 "2018-01-26T09:11:29Z")

</div>

I have a `_pages` directory containing pages. I can set a permalink in a page’s frontmatter with:

```
permalink /page/test/

```

However, specifying variables doesn’t work:

```
slug: test
permalink /page/:slug/

```

(`slug` is one of the documented [template variables](https://jekyllrb.com/docs/permalinks/#template-variables))

The permalink is processed but the variable is not expanded. The above example produces literally`_site/page/:slug/index.html`

Ultimately I want to specify the permalink as a default in `_config.yml`. I have also tried that but it yields the same result - the permalink is produced but the variables are not expanded.

I am using Jekyll 3.7.0 so I should be bang up to date. I have seen other posts about this behaviour both here, GitHub and StackOverflow. They suggest this was a known issue that was resolved in earlier versions so I expect I am just doing it wrong ?

These things do work for posts. I am trying to do it for pages. **How do I specify variables in a pages’ permalinks** , in both frontmatter and defaults, but especially in defaults?

* * *

#### Further information

Having played around with this for a while, I think that variables are expanded but a limited set of variables are available. I think this set is defined by the `url_placeholders` function in `page.rb` and acceptable values are `:path`, `:basename` and `:output_ext`.

I have been able to test permalinks specifed in both frontmatter and the defaults config section and the one that give me the effect that I’m after is `:basename`.

Either frontmatter

```
permalink: /page/:basename/

```

Or defaults

```
defaults:
    - scope:
        path: ""
        type: pages
      values:
        permalink: /page/:basename/

```

However… the behaviour differs between a permalink in frontmatter and one in the defaults config section. The latter causes many files to be generated, like `basename` iterates over `feed`, `index`, `lunr-en`, `main`, `robots`, `sitemap` as well as `test` which is the one that was expected.

I fixed this by expressing the defaults like this:

```
defaults:
    - scope:
        path: "_pages"
      values:
        permalink: /page/:basename/

```

This works for me but I am not sure whether it is the right thing to do.

---

<div class="post-metadata">

**Author:** ![mmistakes](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/mmistakes/32/2169_2.png) [@mmistakes](https://talk.jekyllrb.com/u/mmistakes)\
**Post date:** [January 26, 2018, 3:36pm UTC](https://talk.jekyllrb.com/t/using-permalink-template-varaibles-on-pages/1406/2 "2018-01-26T15:36:45Z")

</div>

One of my theme’s users was [bit by this same thing](https://github.com/mmistakes/minimal-mistakes/issues/1475#issuecomment-357938315). When you set a front matter default and limit the scope to `type: pages` it hits every “page”.

Meaning anything with front matter that isn’t a collection (or post). That’s why you’re seeing it apply the `basename` to `feed`, `index`, `lunr-en`, etc.

You have to limit the scope to just the pages in `_pages`, which is what you’ve done. As far as I know that’s the correct way to go about it.

---

<div class="post-metadata">

**Author:** ![johnlane](https://avatars.discourse-cdn.com/v4/letter/j/eb8c5e/32.png) [@johnlane](https://talk.jekyllrb.com/u/johnlane)\
**Post date:** [January 26, 2018, 4:20pm UTC](https://talk.jekyllrb.com/t/using-permalink-template-varaibles-on-pages/1406/3 "2018-01-26T16:20:32Z")

</div>

Hey @mmistakes. I’ve since found another problem which I am researching -you may have already encountered this one…

I’ve found that, with my config as shown at the end of my post, everything works UNTIL you add a paginated (v2) collection to a page. That is to say that adding frontmatter:

```
pagination:
  enabled: true
  collection: whatever

```

causes the link between the page and the defaults to break. The pages return to being rendered under `:basename` (literally) and any other defaults (such as `author_profile` and `layout`) are ignored.

I haven’t yet a clue why this is…

---

<div class="post-metadata">

**Author:** ![mmistakes](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/mmistakes/32/2169_2.png) [@mmistakes](https://talk.jekyllrb.com/u/mmistakes)\
**Post date:** [January 26, 2018, 5:02pm UTC](https://talk.jekyllrb.com/t/using-permalink-template-varaibles-on-pages/1406/4 "2018-01-26T17:02:31Z")

</div>

Not sure on that one. If I had to guess its related to how jekyll-paginate-v2’s page generation works or when it hooks into Jekyll.

I’m not really familiar with those internals to say. Perhaps reach out to the developer of that plugin to see if they have any ideas?

---

<div class="post-metadata">

**Author:** ![johnlane](https://avatars.discourse-cdn.com/v4/letter/j/eb8c5e/32.png) [@johnlane](https://talk.jekyllrb.com/u/johnlane)\
**Post date:** [January 26, 2018, 6:57pm UTC](https://talk.jekyllrb.com/t/using-permalink-template-varaibles-on-pages/1406/5 "2018-01-26T18:57:21Z")

</div>

Yes, I’ve created an [isolated test](https://github.com/johnlane/jekyll-test-page-permalink) and opened an [issue](https://github.com/sverrirs/jekyll-paginate-v2/issues/74) at `sverrirs/jekyll-paginate-v2`.

---

<div class="post-metadata">

**Author:** ![ibrado](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/ibrado/32/768_2.png) [@ibrado](https://talk.jekyllrb.com/u/ibrado)\
**Post date:** [February 2, 2018, 3:43pm UTC](https://talk.jekyllrb.com/t/using-permalink-template-varaibles-on-pages/1406/6 "2018-02-02T15:43:55Z")

</div>

Please check my patch for permalink defaults in your JPv2 issue, @johnlane. Thanks!
