# Overriding defaults in layout frontmatter does not affect page

**URL:** <https://talk.jekyllrb.com/t/overriding-defaults-in-layout-frontmatter-does-not-affect-page/1452>\
**Category:** Help\
**Created:** [February 5, 2018, 12:18pm UTC](https://talk.jekyllrb.com/t/overriding-defaults-in-layout-frontmatter-does-not-affect-page/1452 "2018-02-05T12:18:23Z")\
**Posts on this page:** 4\
**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:** [February 5, 2018, 12:18pm UTC](https://talk.jekyllrb.com/t/overriding-defaults-in-layout-frontmatter-does-not-affect-page/1452/1 "2018-02-05T12:18:23Z")

</div>

If I have a frontmatter on a layout that sets a variable, does that variable apply on the page ?

I have a page with frontmatter and content

```auto
---
layout: test
---
{{ myvalue }}

```

and I have a layout called `test` with frontmatter

```auto
---
myvalue: foo
---

```

The page does not display `foo`.

Having read [this tutorial](https://jekyllrb.com/tutorials/orderofinterpretation/#variable-on-page-not-rendered-because-variable-is-assigned-in-layout) I think **this doesn’t work because the layout is processed after the page** , although that is talking about variables assigned in a layout’s liquid rather than its front matter.

My use case is to override defaults when a specific layout is used. So I have defaults defined in `_config.yml` but want to change some of those when a specific layout is used. Perhaps there is another way…?

---

<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:** [February 5, 2018, 1:19pm UTC](https://talk.jekyllrb.com/t/overriding-defaults-in-layout-frontmatter-does-not-affect-page/1452/2 "2018-02-05T13:19:22Z")

</div>

Page variables in front matter are accessed via the `page` object while layout front matter is `layout`.

What you probably want to do is use `assign` to set a new variable that defaults to `layout.myvalue` but can be overided at the page level.

Something like this:

```auto
{% assign myvalue = page.myvalue | default: layout.myvalue %}

```

And you’d access it with `{{ myvalue }}` which should output `foo`. If you set `myvalue: bar` in a page’s front matter instead of the layout it should output `bar`.

---

<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:** [February 5, 2018, 2:43pm UTC](https://talk.jekyllrb.com/t/overriding-defaults-in-layout-frontmatter-does-not-affect-page/1452/3 "2018-02-05T14:43:27Z")

</div>

Hi @mmistakes, what I am trying to do is set the theme’s `toc` setting in a layout instead of setting it in the page.

I have `toc: true` set as a default in `_config.yml` but I want to disable it for my index pages. I have a `_layouts/index.md` file where I set `toc: false` in the frontmatter hoping that pages using that layout would not get a toc. But it doesn’t work like that.

If I have to set _something_ in the page file then I might as well do `toc: false` in its frontmatter. It’s what I am doing now but I hoped that I could factor that out to the layout.

Sorry - I posed the question in a generic way rather than calling out the theme… 🙂

---

<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:** [February 5, 2018, 3:14pm UTC](https://talk.jekyllrb.com/t/overriding-defaults-in-layout-frontmatter-does-not-affect-page/1452/4 "2018-02-05T15:14:24Z")

</div>

Ah yeah that’s the problem. The theme looks for `page.toc` not `layout.toc`.

Your best bet would be to set a [front matter default](https://jekyllrb.com/docs/configuration/#front-matter-defaults) and scope it to the pages you want that value for.
