Skip to content

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.

Extension

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>
}

Inclusion

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.

Clone this wiki locally