PAGENODE

About Documentation Github

Presenting Content

PHP is a templating language, so Pagenode doesn't bother to re-invent the wheel. Simply include a .php file and be done with it.

If you loathe the idea of using PHP for templates, you can of course bring along another template engine. But before you do so, please read on. Modern PHP is quite a nice fit for Pagenode templates.

route('/', function() {
    $node = select('nodes/')->one(['keyword' => 'hello']);
    include('templates/node.html.php');
});

You can use PHPs new-ish short tags to print variables. All keys and values from your Nodes header section are accessible as properties of the node. All values are escaped by Pagenode, so there's no need to call htmlSpecialChars() yourself:

<h1>
    <?= $node->title ?>
</h1>

How you structure your templates is totally up to you. However, I recommend to at least divide your templates in header, footer and content parts. E.g.:

templates/head.html.php:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title><?= $node->title ?? 'Pagenode' ?></title>
</head>
<body>

templates/foot.html.php:

</body>
</html>

templates/node.html.php:

<?php include('templates/head.html.php'); ?>

<h1>
    <?= $node->title ?? 'Untitled' ?>
</h1>

<?= $node->body ?>

<p class="foot">
    Created at <?= $node->date->format('Y.m.d') ?>,
    Tags:
    <?php foreach ($node->tags as $tag) {?>
        <a href="/nodes/<?= $tag ?>"><?= $tag ?></a>
    <?php } ?>
</p>

<?php include('templates/foot.html.php'); ?>

Again, no need to escape anything.

Note the ?? in <?= $node->title ?? 'Untitled' ?>. The null coalescing operator is perfect for providing defaults.

$node->date->format() accepts the same format string as PHPs date function, but you can also just use $node->date to get it in the configurable PN_DATE_FORMAT.

That's all there is to Pagenode. Have a look at the API-Reference and Configuration Options for the remaining details.

© 2024 Dominic Szablewski – rendered in (2.9ms)