# Exclude file from build based on front-matter variable value for a given environment

**URL:** <https://talk.jekyllrb.com/t/exclude-file-from-build-based-on-front-matter-variable-value-for-a-given-environment/6391>\
**Category:** Help\
**Created:** [September 4, 2021, 6:47pm UTC](https://talk.jekyllrb.com/t/exclude-file-from-build-based-on-front-matter-variable-value-for-a-given-environment/6391 "2021-09-04T18:47:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![deepfriedbrain](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/deepfriedbrain/32/360_2.png) [@deepfriedbrain](https://talk.jekyllrb.com/u/deepfriedbrain)\
**Post date:** [September 4, 2021, 6:47pm UTC](https://talk.jekyllrb.com/t/exclude-file-from-build-based-on-front-matter-variable-value-for-a-given-environment/6391/1 "2021-09-04T18:47:53Z")

</div>

I would like to exclude certain files from the build based on the value of a variable defined in the front-matter of the files for a given environment.

For example, if the environment is `staging`, and the file front-matter contains a variable `test` with value `true` (`test: true`), I want to entirely exclude this file from the `staging` build only.

Is this possible?

I know about the `exclude` variable in the `_config.yml` and understand how it works, but I have many files in different folders and it’s a lot of effort to manually list them in the `exclude` variable and keep the list updated as new files are added. I need a simpler approach such as the one I described.

Thanks.

---

<div class="post-metadata">

**Author:** ![chuckhoupt](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/chuckhoupt/32/523_2.png) [@chuckhoupt](https://talk.jekyllrb.com/u/chuckhoupt)\
**Post date:** [September 4, 2021, 9:09pm UTC](https://talk.jekyllrb.com/t/exclude-file-from-build-based-on-front-matter-variable-value-for-a-given-environment/6391/2 "2021-09-04T21:09:02Z")

</div>

I think the only straightforward way to do this would be to write a plugin.

A more crooked way is to use a two stage build process. The first jekyll-build would use Liquid to generate a `_staging_config.yml` file that has a long `exclude` list of test pages. The second jekyll-build would use the generated exclude list to build the staging site (via `--config _config.yml,_staging_config.yml`). This might be a tolerable solution if it is all hidden inside a build script or Makefile (but still a bit squirrelly).

---

<div class="post-metadata">

**Author:** ![deepfriedbrain](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/deepfriedbrain/32/360_2.png) [@deepfriedbrain](https://talk.jekyllrb.com/u/deepfriedbrain)\
**Post date:** [September 5, 2021, 6:04am UTC](https://talk.jekyllrb.com/t/exclude-file-from-build-based-on-front-matter-variable-value-for-a-given-environment/6391/3 "2021-09-05T06:04:10Z")

</div>

Good idea. It does the job for now. Thank you!
