Pass param to include

Hi,

It is possible to pass a param to an included file? {{.Include "path/to/file.html"}}

or anyway to achieve something like this:

{{.Include "path/to/file.html" .param.name="John"}}

and in file.html

Hello {{.param.name}}

Thanks.

Nope, but I suppose someone could look into whether this is trivial to implement. If so, we could accept it as a change.

Did someone look at this feature ?

Thanks.

If you post this as an issue in the github repository, someone may have time to take a look at it.

 https://github.com/mholt/caddy/issues
1 Like

I actually just needed something like this this weekend. I’m implementing it like so:

{{.Include "path/to/file.html" "arg1" "arg2"}}

and then inside file.html:

{{index .Args 0}}   <!-- arg1 -->
{{index .Args 1}}   <!-- arg2 -->

Would that be acceptable? In my case, I need to pass a <title> value into the included header file. So this works for me. But I’m still double-checking if this is how I want it to look in Caddy, or if it should be sugared up a bit with a syntax like this:

{{.Param 0}}

Meaning, “the value of parameter 0” – or maybe “argument” is technically more correct and I don’t need to add any sugar…

Implemented in 22a266a. @geodeveloper

I went with the {{index .Args N}} syntax for now.

Thank you! I’m glad this was implemented! Keep up the good work! :slight_smile:

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