Web pages
webNaja is Najova's own way to make web pages: parts like headings, rows and links, written in Najova instead of HTML.
A first page
A page is a .wnaj file. $page holds everything on it, and the first value is the title in the browser's tab.
$page[Sunrise Bakery]
$heading[Sunrise Bakery]
$paragraph[Fresh bread every morning, **from 7 am**.]
$link[See the menu;/menu;look=primary]
$endpage› naja serve, then open /
GET / → 200
<main class="nj-page" id="page">
<h1 class="nj-heading">Sunrise Bakery</h1>
<p class="nj-paragraph">Fresh bread every morning, <strong>from 7 am</strong>.</p>
<a href="/menu" class="nj-button primary">See the menu</a>
</main>In a folder with index.wnaj, type naja serve and open http://localhost:8080/ in your browser. The page reloads by itself each time you save.
Words
$heading and $paragraph hold text. In a paragraph, bold, italic, code and links work as they do in Markdown: write **bold**, *italic* and [links](/menu). $link makes a link on its own line; look=primary makes it a button.
Laying parts out
$row puts parts side by side, and they wrap onto new lines on a phone. $column puts them one under another, and $grid makes columns that become one column on a phone. $items makes a list, with each part inside it as one item.
$page[Opening times]
$heading[Opening times]
$row[gap=24]
$column
$heading[Weekdays;2]
$paragraph[7 am to 6 pm]
$endcolumn
$column
$heading[Weekends;2]
$paragraph[8 am to 2 pm]
$endcolumn
$endrow
$items[type=numbered]
$paragraph[Order online.]
$paragraph[Pick it up warm.]
$enditems
$endpage› naja serve, then open /
GET / → 200
<main class="nj-page" id="page">
<h1 class="nj-heading">Opening times</h1>
<div class="nj-row" style="gap:24px">
<div class="nj-column">
<h2 class="nj-heading" id="weekdays">Weekdays</h2>
<p class="nj-paragraph">7 am to 6 pm</p>
</div>
<div class="nj-column">
<h2 class="nj-heading" id="weekends">Weekends</h2>
<p class="nj-paragraph">8 am to 2 pm</p>
</div>
</div>
<ol class="nj-items">
<li><p class="nj-paragraph">Order online.</p></li>
<li><p class="nj-paragraph">Pick it up warm.</p></li>
</ol>
</main>Pages from your data
A page is Najova, so names, lists and blocks work in it. Here a table is filled from a list with $each. The prices are in quotes so they stay as written: a number drops its last 0.
$let[menu;$list]
$add[$get[menu];$table[name;Sourdough;price;"4.50"]]
$add[$get[menu];$table[name;Rye;price;"3.80"]]
$add[$get[menu];$table[name;Bagel;price;"1.20"]]
$page[Menu]
$heading[Menu]
$sheet[Bread;Price]
$each[b;$get[menu]]
$cells[$get[b.name];\$$get[b.price]]
$endeach
$endsheet
$paragraph[$count[$get[menu]] kinds today.]
$endpage› naja serve, then open /
GET / → 200
<main class="nj-page" id="page">
<h1 class="nj-heading">Menu</h1>
<div class="nj-sheet"><table><thead><tr><th scope="col">Bread</th><th scope="col">Price</th></tr></thead><tbody>
<tr><td>Sourdough</td><td>$4.50</td></tr>
<tr><td>Rye</td><td>$3.80</td></tr>
<tr><td>Bagel</td><td>$1.20</td></tr>
</tbody></table></div>
<p class="nj-paragraph">3 kinds today.</p>
</main>Your own parts
A $function can be a part. Use it as a block, like $card ... $endcard, and the parts written inside go where $children is. $style gives a part its look: see $style in the reference.
$-- Your own part: the parts written inside it go where $children is.
$function[card;title]
$section[;style=card]
$heading[$get[title];3]
$children
$endsection
$endfunction
$style[card]
padding = 16
corner = 12
border = 1px solid theme.border
$endstyle
$page[Today]
$card[Bread]
$paragraph[Sourdough and rye.]
$endcard
$card[Cakes]
$paragraph[Lemon and carrot.]
$endcard
$endpage› naja serve, then open /
GET / → 200
.s-card{padding:16px;border-radius:12px;border:1px solid var(--border)}
<main class="nj-page" id="page">
<section class="nj-section s-card">
<h3 class="nj-heading" id="bread">Bread</h3>
<p class="nj-paragraph">Sourdough and rye.</p>
</section>
<section class="nj-section s-card">
<h3 class="nj-heading" id="cakes">Cakes</h3>
<p class="nj-paragraph">Lemon and carrot.</p>
</section>
</main>The style's lines become the page's CSS: corner is border-radius, and theme.border is the theme's border colour.
Pages and addresses
| File | Address |
|---|---|
index.wnaj | / |
about.wnaj | /about |
blog/first.html.wnaj | /blog/first.html |
guides/[name].wnaj | /guides/ and any name: $request[path.name] says which |
A file named 404.wnaj answers addresses that have no page. To put the site on a host that only sends files, naja build --web turns it into plain HTML and CSS: see Commands.
Ready-made parts
Some parts do more on their own: $sidebar (it folds into a Menu button on phones), $nav, $tabs, $sheet, $code, $search, $filter, $progress, $themePick, $contents and $form. Each has an example in Pages.