CloudyKit / jet

Jet template engine

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

razonyang opened this issue · comments

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.