ketchup icon indicating copy to clipboard operation
ketchup copied to clipboard

Any partial/include template example?

Open vladyslav2 opened this issue 7 years ago • 5 comments

Hi Octavore.

Thanks for a great product!

Tell me please, is it possible to do something like this in templates:

 <html>                                                       
   <head>
      {{ template "header" . }}  
      // pr
      {{ partial "header". }} <- like hugo do?
   </head>
...

header.html:

{{define "header"}}                                                              
    <meta>                                                                       
    <link rel="stylesheet" ..>
{{end}}

As far as I can see right now, system gives me an error, any ideas how i can do this?

thanks for reply in advance

vladyslav2 avatar Aug 12 '17 16:08 vladyslav2

Thanks for the kind words!

Unfortunately that's not currently possible because the templates are rendered directly from the specified template file without loading other templates, but I do think it's worth supporting. I'll try to put something together :)

octavore avatar Aug 14 '17 08:08 octavore

Great, thank you. Let's leave this ticket open and add enhancement label?

vladyslav2 avatar Aug 14 '17 09:08 vladyslav2

@vladyslav2 this should be fixed now in 0.2.0, you can refer to other template files with e.g. {{ template "path/to/header.html", where path is relative to $THEME_ROOT/templates. let me know!

octavore avatar Aug 21 '17 08:08 octavore

@octavore {{ template "header.html" }} - works

{{ template "partials/header.html" }} - do not works, engine still searching for a template in /templates directory

2017/08/21 13:00:26 [ERROR] error serving page /come-on-come-on [b7ad9a6c-9bf8-41ec-8270-4b0a0b6e16a8]: open data/themes/ketchup-docs/templates/header.html: no such file or directory
2017/08/21 13:00:26 [ERROR] [github.com/ketchuphq/ketchup/server/content/templates/filestore/filestore.go:102] open data/themes/ketchup-docs/templates/header.html: no such file or directory

vladyslav2 avatar Aug 21 '17 10:08 vladyslav2

good catch, I've just pushed a fix to master

octavore avatar Aug 21 '17 16:08 octavore