3 ms·
Both is possible. See here an example how to implement use case 2: https://github.com/ckilb/golang-layout-tpl-example https://github.com/ckilb/golang-layout-tpl
by ckdot2 3y ago
Both is possible. See here an example how to implement use case 2:
https://github.com/ckilb/golang-layout-tpl-example https://github.com/ckilb/golang-layout-tpl-example
I don't like Go's template engine too much, I find it a bit cumbersome in many cases. But it's quite capable.
- shhsshs 3y agoThat is not quite a true "slot" behavior because the containing pages have to have a reference to the main layout via `{{ define "main" }}`
- ckdot2 3y agoYou're right. But this only means that it won't be possible that you use the same template for different slots. Personally, I don't remember I ever needed that. Actually, most template engines I know work this way (https://twig.symfony.com/doc/2.x/templates.html#template-inheritance https://twig.symfony.com/doc/2.x/templates.html#template-inh..., "{% block content %}"). But still, it's easy to archieve that by just creating another sub template. So your first template file is the layout, the second one contains the main block definition, and that definition you just include another sub template which can be reused elsewhere.
- ckdot2 3y agoHere's a blog post which goes more into detail: https://kilb.tech/golang-templates https://kilb.tech/golang-templates