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']);

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:

    <?= $node->title ?>

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.:


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




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

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

<?= $node->body ?>

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

<?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 (3.19ms)