This didn’t really fit the help template so hope its okay if I removed those parts.
V1 Reference:
Long ago I used the suggestion in the link to create a bot/user template. I’m essentially doing this in a template:
{{ $uagent := .Header “User-Agent” }}
{{ $uagent := .Truncate $uagent 4 }}
{{if eq $uagent “xxxx” }}
<insert a template for BOT>
{{else}}
<insert a template for ELSE>
{{end}}
When i’m attempting to do this in V2, the Header isn’t available to parse for the user agent (at least that I could find) so this is failing now and I need another solution.
http.log.error template: templatecombined2:1:14: executing “templatecombined2” at <.Header>: can’t evaluate field Header in type fileserver.browseListing
I have two questions:
Is there a V2 equivalent that I can use to get the header in the template to evaluate it?
Is there a more efficient way to do this in V2 in the configuration itself by using matches?
i.e. something like this:: @template {
header xyz
}
use template xyz
and tell caddy if match to use one template else use the default? That would be far easier than my hacky way I did it previously.
2020/04/23 13:06:11.797 ERROR http.log.error template: templatecombined2:1:18: executing “templatecombined2” at <.Req.Header.Get>: can’t evaluate field Req in type fileserver.browseListing
Along the same lines I get the same type of error when trying to use ‘Replace’ function as well. I’m not sure if it is different issue (Not trying to confuse this thread but figured it may not be worth creating a new one Separately so figured i’d mention )
ERROR http.log.error template: template:29:33: executing "template" at <$.Replace>: can't **evaluate field Replace in type fileserver.browseListing**
Ohhh you’re using templates for the file server’s browse feature, not the templates handler?? That wasn’t clear up front.
The browse template is executed in a totally separate context from that of the templates handler. I don’t have much documented on it right now. We can expand its functionality more in v2.x.
Glad you got it working though Thanks for posting your temporary solution. It’s on my list to make the browse templates as functional as the other ones later.