Caddy 2 part of domain in templates tag

Hey guys, I’m using caddy with wildcard domains. And currently using simple landing page powered by caddy templates. It’s possible to get domain name via templates tags? Actually, needed the first part before the dot. Like domain.com - I need to get “com” via template tag. There’s a lot of domains used, like domain.blog domain.news etc… I need to get “blog”, “news” via template tag. Is it accessible via templates? Or maybe I should set some env variable and pass it to template and read there?

If you use v2.2.0-rc.1, you can use the new placeholder template function to do this:

https://github.com/caddyserver/caddy/pull/3324

The specific placeholder is {http.request.host.labels.*}, documented here:

1 Like

Ohh, awesome. I’ll wait for release. I’m currently using v2.1.1 with cloudflare plugin
Thanks!

You can easily build it from source yourself with xcaddy:

It just involves downloading Go (just unzipping Go somewhere and making sure the binaries path is in your PATH) then downloading xcaddy and running it :+1:

1 Like

Yes, I’m already previously have used xcaddy to build caddy with cloudflare plugin. But I think I should wait for stable caddy version(same caddy also serving other python/nodejs powered apps).

I did it, works as expected, thanks again!!

1 Like

This topic was automatically closed after 30 days. New replies are no longer allowed.