# Defining Front Matter Variables with Data from a \_data File

**URL:** <https://talk.jekyllrb.com/t/defining-front-matter-variables-with-data-from-a-data-file/3518>\
**Category:** Help\
**Created:** [October 30, 2019, 8:25am UTC](https://talk.jekyllrb.com/t/defining-front-matter-variables-with-data-from-a-data-file/3518 "2019-10-30T08:25:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![thekpaul](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/thekpaul/32/1833_2.png) [@thekpaul](https://talk.jekyllrb.com/u/thekpaul)\
**Post date:** [October 30, 2019, 8:25am UTC](https://talk.jekyllrb.com/t/defining-front-matter-variables-with-data-from-a-data-file/3518/1 "2019-10-30T08:25:39Z")

</div>

I have a `_data` file called `nav.yml` that contains all pages and all variables necessary. I also have each individual page in their respective `.md` files. In such a case, can I define front matter variable for my pages and posts from a `_data` file without copying and pasting everything? If not, is there a way to import front matter from each page and record them in a `_data` file?

`EDIT`: I use submenus in my navigation menu and some pages are not meant to be shown, which is why I would prefer to use `_data` files to organise and keep track of all relevant pages.

---

<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:** [October 30, 2019, 12:57pm UTC](https://talk.jekyllrb.com/t/defining-front-matter-variables-with-data-from-a-data-file/3518/2 "2019-10-30T12:57:01Z")

</div>

Only way I’m aware of setting default front matter is in your \_config.yml using the `defaults` key

> **[Collections](https://jekyllrb.com/docs/step-by-step/09-collections/#front-matter-defaults)**
>
> Let’s look at fleshing out authors so each author has their own page with a blurb and the posts they’ve published.

---

<div class="post-metadata">

**Author:** ![chetabahana](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/chetabahana/32/1639_2.png) [@chetabahana](https://talk.jekyllrb.com/u/chetabahana)\
**Post date:** [November 4, 2019, 11:16pm UTC](https://talk.jekyllrb.com/t/defining-front-matter-variables-with-data-from-a-data-file/3518/3 "2019-11-04T23:16:43Z")

</div>

> [@thekpaul](#):
>
> If not, is there a way to import front matter from each page and record them in a `_data` file?

Neither way is possible with `jekyll`. However you may generate it on a fly using site variables like so:

`  
{% assign feeds = site.feeds | sort: ‘weight’ %}  
{% for feed in feeds %}

(do collection…)

{% endfor %}  
`.

Take a look in [this sample](https://chetabahana.github.io/feed.json).
