Skip to content

Commit

Permalink
Update layout syntax in readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Wuvist committed Jun 2, 2019
1 parent 59c4a59 commit 06a5cb5
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ like:
"tpl/layout" //import tpl/layout namespace
)
var layout *layout.Base //Use layout package's **base struct** for layout
layout := layout.Base //Use layout package's **Base func** for layout
var user *models.User //1st template param
var blog *models.Blog //2nd template param
}
Expand Down Expand Up @@ -176,11 +176,13 @@ The syntax for declaring layout is a bit tricky, in the example mentioned above:
"tpl/layout"
)
var layout *layout.Base //Use layout package's **base struct** for layout
layout := layout.Base //Use layout package's **base func** for layout
}
```
`"tpl/layout"` **is** a the layout package namespace, and the `layout` variable refers to `"layout.Base"` structure, which should be generated by `tpl/layout/base.gohtml`.
`"tpl/layout"` **is** a the layout package namespace, and the `layout` variable refers to `"layout.Base"` func, which should be generated by `tpl/layout/base.gohtml`.
> Must use `layout` as the variable name
### Package / Variable convention
Expand Down Expand Up @@ -220,6 +222,7 @@ It's just a usual gorazor template, but:
* First param must be `var body string` (As it's always required, maybe we could remove it in future?)
* All params **must be** string, each param is considered as a **section**, the variable name is the **section name**.
* Under `layout` package, i.e. within "layout" folder.
* Optionally, use `isLayout := true` to declare a template as layout
A template using such layout `tpl/index.gohtml` may look like:
Expand All @@ -229,7 +232,7 @@ A template using such layout `tpl/index.gohtml` may look like:
"tpl/layout"
)
var layout *layout.Base
layout := layout.Base
}
@section footer {
Expand All @@ -239,6 +242,18 @@ A template using such layout `tpl/index.gohtml` may look like:
<h2>Welcome to homepage</h2>
```
It's also possible to use import alias:
```html
@{
import (
share "tpl/layout"
)
layout := share.Base
}
```
With the page, the page content will be treated as the `body` section in layout.
The other section content need to be wrapped with
Expand Down

0 comments on commit 06a5cb5

Please sign in to comment.