BlogHow-toPages

How to add a page to Palatian, from the starter page

Duplicate starter.html, keep the partials and the content wrapper, add a link in the panel so the command bar finds it, and register page JavaScript if you need any. The same for the React edition, with a page component and a route.

3 min readPerforks

A new page made from starter.html, with its data-page attribute, the content wrapper and its link in the panel

The quickest way to a new page is starter.html: a blank page with the full shell, dock, panel, toolbar, footer and every automation loaded. Duplicate it, change the title and the content, and link it from the panel. How you do that depends on whether you use the build.

With the build (editing src/)

  1. Copy src/starter.html to src/reports-weekly.html. A page is a few partials around your content:
    {{> head title="Weekly report"}}
    {{> nav page="reports-weekly"}}
    {{> toolbar section="Home" title="Weekly report"}}
          <main class="pl-content">
            <div class="pl-page-header">
              <div><h1>Weekly report</h1><p class="pl-page-lede">What this page is for.</p></div>
              <div class="pl-page-actions"><button class="btn btn-primary">Action</button></div>
            </div>
            <div class="row g-3"> … tiles … </div>
          </main>
    {{> footer}}
    {{> scripts}}
    Keep the <main class="pl-content"> wrapper and the page header; everything inside inherits the theme, dark mode, the schemes and the user's preferences.
  2. The page value of the nav partial becomes <body data-page="reports-weekly">, and the section of the toolbar partial decides which dock section is lit.
  3. Add a link in src/partials/nav.hbs, inside the .pl-panel-section of the section it belongs to:
    <a class="pl-panel-link" href="reports-weekly.html"><i class="palatian palatian-file-report"></i>Weekly report</a>
    The command bar reads the panel links, so the page appears in Ctrl/⌘ K with no extra work, and the active page's link is highlighted automatically.
  4. Run npm run dev to see it, or npm run build to write it to dist/. Vite picks up every src/*.html file by itself.

A new section in the dock

A section is one button in the dock and one block in the panel, both in nav.hbs:

<!-- dock -->
<button class="pl-dock-btn" data-section="reports" data-bs-toggle="tooltip" data-bs-placement="right" data-bs-title="Reports">
  <i class="palatian palatian-file-report"></i>
</button>
<!-- panel -->
<div class="pl-panel-section" data-section="reports" data-title="Reports" data-sub="Weekly and monthly">
  <a class="pl-panel-link" href="reports-weekly.html"><i class="palatian palatian-calendar"></i>Weekly</a>
</div>

JavaScript for the page

Most things need no script: toasts, confirms, filters, counters, data tables, sortable lists and the inspector are data-pl-* attributes, and charts can be declared with data-pl-chart or data-pl-sparkline on pages that load palatian-charts.js. If a page needs its own code, add a function to src/js/pages/ and register it in src/js/pages/index.js under the page's name; the engine calls it when body[data-page] matches, after the shell has initialised.

Without the build (editing dist/)

Copy any built page, for example dist/starter.html, rename it and change the content between the toolbar and the footer. Add its link to the panel in every page you want it reachable from, since the partials are already expanded into each file. Because the built pages carry a Content Security Policy, keep the small inline script in the head exactly as it is; see troubleshooting.

In the React edition

  1. Create react/src/pages/ReportsWeekly.jsx. Call usePageEngine() at the top so the data-pl-* automations, forms and declarative charts are scanned; pass { init } for a chart init if you have one:
    import { usePageEngine } from '../hooks/usePageEngine.js'
    
    export const meta = { title: 'Weekly report', section: 'Home' }
    
    export default function ReportsWeekly() {
      usePageEngine()
      return (
        <main className="pl-content">
          …any markup from the HTML edition, with className / htmlFor / defaultValue…
        </main>
      )
    }
  2. Add the route to src/routes.generated.js and a link in src/nav.generated.js. If you prefer to keep writing pages as HTML, add the page to src/, build, and run npm run generate in react/ again: it regenerates the components, routes and nav from dist/.

The shell's classes and the stat tile, inspector, command bar and toast markup are documented in documentation/index.html of your download, with a page on each component.