CloudyKit / jet

Jet template engine
Apache License 2.0
1.26k stars 106 forks source link

Does block support default value or can be marked as optional? #144

Closed razonyang closed 4 years ago

razonyang commented 4 years ago

Hi, I am looking for something like html/template provided:

<title>{{block "title" .}}Default Title{{end}}</title>

If block wasn't imported or defined, ignore it or output the default value.

<!-- layouts/main.html -->
<!DOCTYPE html>
<html>
<head>
</head>
<body>
    {{ yield body() }}
    <script src="/static/js/app.js"></script>
    // ... JS
    {{ yield endBody() }}
</body>
</html>

<!-- site/index.html -->
{{ extends "layouts/index.tmpl" }}

{{ block endBody() }}
  // page js...
{{ end }}
{{ block body() }}
    Hello world.
{{ end }}

The templates works fine, but most of pages no need to define endBody, is there a way to mark block as optional? So that no need to define endBody block in every template. I also noticed there is a IncludeIfExists syntax, but seems not suit for this case.