-
Notifications
You must be signed in to change notification settings - Fork 46
Page splicing
Thomas Weber edited this page Jun 14, 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.
The page-splicing quasis {| p |} allow it to compose a page from other pages.
Using this, it is e.g. possible to built templates that can be extended or snippets that can be included.
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.