About templates
Templates are the skeletons of your pages, and are used by Creators to build pages. A template can be used as much time as needed to build pages.
For example, this documentation site is built with ssgo and uses a single template for all the documentations pages (pages under /docs).
Templates are used through the first argument of the buildPage function, that is given to every creator default exported function as first parameter.
// my-creator.ts
export default (buildPage) => {
buildPage(
"my-template.html", // <-- the path of the template to use (relative to the root of the templates/ directory)
contextData,
{ filename: "my-page.html" }
)
}
ssgo templates allow you to do the following things:
- Text interpolation
- Evaluate tag's attributes at built time
- Show elements conditionnally
- Iterate over data
Some helpers are also automatically provided to page builds contexts under the ssgo key:
ssgo.assrc((expression: any) => string): Using tosource under the hood,assrcallows you to convert a JavaScript expression to its textual representation (ex:ssgo.assrc([1, 2, 3]) === '[1, 2, 3]'). It can be really useful when usingssgowith AlpineJS, when populatingx-dataattributes using theeval:prefix. Check out an usage example in the sidebar component of this website.
Something about this page is wrong? Edit it on GitHub.
