Snippet / Import woes

So I’m trying to wrap my head around snippets and imports, and trying to apply it to the following:

$ tree /config
├── Caddyfile
└── domains
    ├── domain1.com
    └── domain2.com

$ cat /config/Caddyfile
import domains/*

If I modify Caddyfile to the following:

(test) {
	root /www
}
import domains/*

And try to use it in domains/domain1.com like so:

foo.domain1.com {
	import test
}

I get the following error:
“Error during parsing: File to import not found: /config/domains/test”

If I create the snippet in domains/domain1.com (where I use it), I get the same error :confused:

So what I gathered from this is that I can’t use snippets in imported files, this seems unintentional / bugged.

Hi @p3lim,

No, snippets are only usable in the main Caddyfile itself, it doesn’t cross the “import boundary”.

I believe it’s always been this way, but the docs don’t mention this limitation. If you’d like, open an issue at https://github.com/mholt/caddy/issues/new - either as a feature request, or to get the docs updated.

https://github.com/mholt/caddy/issues/2312

1 Like

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