diff options
author | Tim Culverhouse <tim@timculverhouse.com> | 2021-09-17 14:00:36 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-17 13:00:36 -0600 |
commit | 5fda9610f907482497a7b32abb2ab2f85a4e6906 (patch) | |
tree | 847479be65b3267276ce2ea3a79be10c3e723c16 /modules/caddyhttp/templates/templates.go | |
parent | 3f2c3ecf85b590473030b21fd2b5fc9c8ef88744 (diff) |
templates: Add 'import' action (#4321)
Related to (closed) Issue #2094 on template inheritance. This PR adds a new function called "import" which works like "include", except it only takes one argument and passes it to the referenced file to be used as "." in that file.
* Update tplcontext.go
Add {{ render "/path/to/file.ext" $data }} via funcRender
* Update tplcontext.go
* Refactor funcInclude, add funcImport to enable {{block}} and {{template}}
* Fix funcImport return of nil showing up in html
* Update godocs for and
Diffstat (limited to 'modules/caddyhttp/templates/templates.go')
-rw-r--r-- | modules/caddyhttp/templates/templates.go | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/modules/caddyhttp/templates/templates.go b/modules/caddyhttp/templates/templates.go index 6fed8c8..8f2ea2c 100644 --- a/modules/caddyhttp/templates/templates.go +++ b/modules/caddyhttp/templates/templates.go @@ -91,9 +91,25 @@ func init() { // {{httpInclude "/foo/bar?q=val"}} // ``` // +// ##### `import` +// +// Imports the contents of another file and adds any template definitions to the template stack. If there are no defitions, the filepath will be the defition name. Any {{ define }} blocks will be accessible by {{ template }} or {{ block }}. Imports must happen before the template or block action is called +// +// **filename.html** +// ``` +// {{ define "main" }} +// content +// {{ end }} +// +// **index.html** +// ``` +// {{ import "/path/to/file.html" }} +// {{ template "main" }} +// ``` +// // ##### `include` // -// Includes the contents of another file. Optionally can pass key-value pairs as arguments to be accessed by the included file. +// Includes the contents of another file and renders in-place. Optionally can pass key-value pairs as arguments to be accessed by the included file. // // ``` // {{include "path/to/file.html"}} // no arguments |