# Path to content file from project root

**URL:** <https://discourse.gohugo.io/t/path-to-content-file-from-project-root/44262>\
**Category:** feature\
**Created:** [May 8, 2023, 5:56pm UTC](https://discourse.gohugo.io/t/path-to-content-file-from-project-root/44262 "2023-05-08T17:56:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [May 8, 2023, 5:56pm UTC](https://discourse.gohugo.io/t/path-to-content-file-from-project-root/44262/1 "2023-05-08T17:56:30Z")

</div>

With this content file:

```plaintext
/home/user/project/content/en/about.md

```

`{{ .File.Filename }}` returns:

```plaintext
/home/user/project/content/en/about.md

```

**But what I really really want is:**

```plaintext
/content/en/about.md

```

If I add `PWD` to `security.funcs.getenv` I can do this:

```auto
{{ strings.TrimPrefix (os.Getenv "PWD") .File.Filename }}

```

But this approach is somewhat fragile (e.g., executing hugo from another dir with `hugo -s something`).

Running `hugo config` (with or without a `-s` flag) shows:

```plaintext
workingdir = "/home/user/project"

```

So we have access to the value to trim, somewhere.

Justification: avoid hardcoding `contentDir` when interacting with GitHub, GitLab, etc. For example:

> <https://github.com/gohugoio/gohugoioTheme/blob/master/layouts/partials/page-edit.html#L1>

---

<div class="post-metadata">

**Author:** ![iaeiou](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/iaeiou/32/15332_2.png) [@iaeiou](https://discourse.gohugo.io/u/iaeiou)\
**Post date:** [May 9, 2023, 6:47am UTC](https://discourse.gohugo.io/t/path-to-content-file-from-project-root/44262/2 "2023-05-09T06:47:43Z")

</div>

Hi there,

I’m not familiar with this part of Hugo, but I played in the past with filenames and path to provide [a shortcode to embed a file into another](https://roneo.org/en/hugo-include-another-file-with-a-shortcode/#solution), maybe you can find interesting bits out there?  
I’m thinking of `.Page.File.Dir`, see also the references and untested methods

Sorry if I’m off-topic, and good luck

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [May 20, 2023, 4:45pm UTC](https://discourse.gohugo.io/t/path-to-content-file-from-project-root/44262/3 "2023-05-20T16:45:14Z")

</div>

This is resolved in the next release, presumably v0.112.0, with [https://github.com/gohugoio/hugo/pull/10971](https://github.com/gohugoio/hugo/pull/10971).

Thank you bep.

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [May 22, 2023, 4:45pm UTC](https://discourse.gohugo.io/t/path-to-content-file-from-project-root/44262/4 "2023-05-22T16:45:46Z")

</div>

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.
