Golang Template-2: Template composition and how to organize template files ?

define action

{{define "templ_name"}}second template{{end}}

template action

{{template "templ_name" }}
{{template "templ_name" pipeline}}

block action

Block action is defining a template and executing in place.

{{block "name" pipeline}} huuw {{end}}
  • Template composition(nested template or template embedding or template inheritance) can be achieved.
  • Empty template can be used as placeholder templates.

How to organize template files ?

We keep our template files in two directories. One is the layout and other is the application specific views. The layout will contain base template and other common templates.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store