# \[SOLVED\] Get Draft Front Matter without Generating Page?

**URL:** <https://discourse.gohugo.io/t/solved-get-draft-front-matter-without-generating-page/18259>\
**Category:** support\
**Created:** [April 23, 2019, 9:34am UTC](https://discourse.gohugo.io/t/solved-get-draft-front-matter-without-generating-page/18259 "2019-04-23T09:34:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![HenrySkup](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/henryskup/32/8183_2.png) [@HenrySkup](https://discourse.gohugo.io/u/HenrySkup)\
**Post date:** [April 23, 2019, 9:34am UTC](https://discourse.gohugo.io/t/solved-get-draft-front-matter-without-generating-page/18259/1 "2019-04-23T09:34:42Z")

</div>

Hey, I was wondering if there is a way to get content from pages where `draft = true` without actually generating the page in the build.

Use case:

I have a directory of pages each with a `.Title` and some are ready to be published, others not. However, I would like to list all the pages linking to the ones where `draft = false` and just putting the `.Title` when `draft = true`. This would prevent people from navigating to the (still in draft) page if they can figure out the URL – which should be pretty simple.

Some code (not tested - but in theory it should work (I might be missing some `.Params` or something, but the intent should be clear)

```auto
// Directory
...
│
├── content/
│ ├── post-1.md // title = "Hello Hugo" author="Mr. X" draft = false
│ ├── post-2.md // title = "Another Title" author="Mr. Y" draft = true
│ ├── post-3.md // title = "Yet Another Title" author="Mrs. Z" draft = false
│ └── _index.md // draft = false
...

```

This is really where the question is (I am 100% sure this is not correct 😛)

```auto
// layout/_default/list.html

{{ range .Pages }}
    <div>
    {{ if eq .draft true }}
        {{ .Title }}
    {{ else }}
        <a href="{{ .Permalink }}">{{ .Title }}</a>
    {{ end }}
    <span>By: {{ .author }}</span>
    </div>
{{ end }}

```

```auto
// Desired Output Directory

...
│
├── pages/
│ ├── post-1.html
│ ├── post-3.html
│ └── index.html
...

```

```auto
// Desired Output in /pages/index.html

<div>
     <a hrfe=".../posts/post-1.html">Hello Hugo</a>
     <span>By: Mr. X</span>
</div>
<div>
     <span>Another Title</span>
     <span>By: Mr. Y</span>
</div>
<div>
    <a hrfe=".../posts/post-1.html">Yet Another Title</a>
     <span>By: Mrs. Z</span>
</div>

```

I think that this could be very useful for book and documentation websites which want to indicate that particular content is in the works, but is not ready for public consumption. I would be interested if people have other use cases.

-hs

---

<div class="post-metadata">

**Author:** ![pointyfar](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/pointyfar/32/5797_2.png) [@pointyfar](https://discourse.gohugo.io/u/pointyfar)\
**Post date:** [April 23, 2019, 10:13am UTC](https://discourse.gohugo.io/t/solved-get-draft-front-matter-without-generating-page/18259/2 "2019-04-23T10:13:07Z")

</div>

I don’t think that’s going to work that way. Drafts are either published (ie using `--buildDrafts`), or not. This means when it’s published, it has a `.Permalink`, and therefore browse-able.

You can get the `draft` state of a `.Page` with `.Params.draft`, but again, the above point stands.

You could look into headless bundles: [https://gohugo.io/content-management/page-bundles/#headless-bundle](https://gohugo.io/content-management/page-bundles/#headless-bundle)

Basically, have a headless bundle to contain all your non-browse-able content. These will not have a `.Permalink`, but they will also not be part of `.Site.Pages`. You can use `.Resources` methods to get their content etc.: [https://gohugo.io/content-management/page-resources/](https://gohugo.io/content-management/page-resources/)

Once you are ready to have them published, just move out of the headless bundle.

---

<div class="post-metadata">

**Author:** ![HenrySkup](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/henryskup/32/8183_2.png) [@HenrySkup](https://discourse.gohugo.io/u/HenrySkup)\
**Post date:** [April 23, 2019, 10:48am UTC](https://discourse.gohugo.io/t/solved-get-draft-front-matter-without-generating-page/18259/3 "2019-04-23T10:48:35Z")

</div>

Hmmm, interesting – that could work in another context. I’m building this for Forestry, so I don’t think that it would fit within their [current] editing workflow.

I feel that this could be fairly useful and since Hugo is already going through all the pages to check if `draft = true` or not, I could imagine that it could easily store all front matter / content, and then filters out all the drafts when it writes to `public/`

---

<div class="post-metadata">

**Author:** ![HenrySkup](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/henryskup/32/8183_2.png) [@HenrySkup](https://discourse.gohugo.io/u/HenrySkup)\
**Post date:** [April 24, 2019, 6:06am UTC](https://discourse.gohugo.io/t/solved-get-draft-front-matter-without-generating-page/18259/4 "2019-04-24T06:06:55Z")

</div>

`readFile` + `transform.Unmarshal` is the way to go (for now)  
(i’m not sure if .Content / .RawContent is available, but at least for my application right now, that is not necessary)

> **[transform.Unmarshal](https://gohugo.io/functions/transform.unmarshal/)**
>
> \`transform.Unmarshal\` (alias \`unmarshal\`) parses the input and converts it into a map or an array. Supported formats are JSON, TOML, YAML and CSV.
