-
Notifications
You must be signed in to change notification settings - Fork 42
Page splicing
James Cheney edited this page Jun 15, 2017
·
3 revisions
When writing larger applications it may become necessary for readability and reusability to split XML/page code into smaller parts and compose pages from these.
XML code can be spliced into a page using ordinary braces {...}
. However, certain features (such as formlet rendering) cannot be used in XML fragments but instead can only be used in pages.
The page-splicing quasis {| p |}
allow it to compose a page from other pages.
Using this, it is e.g. possible to build templates that can be extended or snippets that can be included in other pages, where the included pages make use of formlets.
sig myTemplate : (Page, Page) ~> Page
fun myTemplate (content, sidebar) {
page
<html>
<head>
<!-- boilerplate head-code -->
</head>
<body>
<header><!-- global header --></header>
<main>
{| content |}
</main>
<aside>
{| sidebar |}
</aside>
<footer><!-- global footer --></footer>
</body>
</html>
}
var myCoolWidget = page <div class="cool-widget"> ... </header>;
page
<html>
<head> ... </head>
<body>
<main> Other content</main>
<aside>{| myCoolWidget |}</aside>
</body>
</html>
Note: When providing such resuable snippets, avoid using IDs in the XML, as there is no guarantee the snippet is used ony once and IDs should be unique.