jet icon indicating copy to clipboard operation
jet copied to clipboard

Templates in nested folders

Open emaborsa opened this issue 4 months ago • 0 comments

I am trying to figure out, if nesting jet templates into folders is supported.

I have this structure:

/templates
  /_shared
    body.jet
  /layouts
    base-auth.jet
    base-public.jet
  /pages
    login.jet

login.jet, the first line:

{{ extends "layouts/base-public.jet" }}

base-public.jet

{{ include "_shared/body.jet" }}

{{ block body() }}
<div class="wrapper">
  <div class="image-container"></div>
    <div class="content">
      <div class="content-wrapper">
        <div class="content-form">
          {{ block contentForm() }}{{ end }}
          <div class="spinner-container">
            <div class="spinner" id="spinner"></div>
          </div>
        </div>
      </div>
  </div>
</div> 
{{ end }}

body.jet:

<!DOCTYPE html>
<html>
  <head>
      {{ block script() }}{{ end }}
  </head>
  <body>
    {{ block body() }}{{ end }}
  </body>
</html>

How i load the templates:

opts := []jet.Option{}
if !cfg.IsProduction() {
	opts = append(opts, jet.InDevelopmentMode())
}

views := jet.NewSet(
	jet.NewOSFileSystemLoader("templates"),
	opts...,
)

Calling tmpl, err := h.view.GetTemplate("pages/login.jet") I get "template: /pages/login.jet:1: template /pages/layouts/base-public.jet could not be found"

Where does this path "/pages/layouts/" come from? I can imagine that calling extends "layouts/base-public.jet" in the login.jet, which is in the pages folder, combines the two paths, how do i extend/include templates from different folders? Is it possible?

emaborsa avatar Dec 01 '25 11:12 emaborsa