Path to content file from project root

With this content file:


{{ .File.Filename }} returns:


But what I really really want is:


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

{{ 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:

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:


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, 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

1 Like

This is resolved in the next release, presumably v0.112.0, with

Thank you bep.


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