ketchuphq / ketchup

A simple CMS :tomato:
https://ketchuphq.com
Apache License 2.0
393 stars 31 forks source link

Any partial/include template example? #6

Open vladyslav2 opened 7 years ago

vladyslav2 commented 7 years ago

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

octavore commented 7 years ago

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 :)

vladyslav2 commented 7 years ago

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

octavore commented 7 years ago

@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!

vladyslav2 commented 7 years ago

@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
octavore commented 7 years ago

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