Can default be used with block?

I’m trying to use default with block as shown below:

<title>{{ block "title" . | default .Title }}</title>

But this doesn’t work as if there is a .Title but no block "title", nothing is shown.

Can these two functions be used together?

Happy new year :partying_face:

Don’t think so. But you ought to put the default in the title block, to operate on the title.

1 Like

No they can’t. The block is only to demark how partials and “sub”-templates are used within your templates. block is not a function in the sense of you using it in a template. It’s a placeholder for something. Then you add the contents of the something in lower templates. You should check there if .Title is set and set a default.

1 Like

Set the default value(s) inside your block, e.g.:

<title>{{ block "title" . }}{{ .Title }}{{ end }}</title>
3 Likes