This guide will show you how to use the Pagenode library and how to get something on the screen quickly.
nodes/
next to itnodes/hello.md
with some Markdown contentindex.php
with the following content:<?php
require_once('pagenode.php');
route('/', function() {
$node = select('nodes/')->one(['keyword' => 'hello']);
include('templates/node.html.php');
});
dispatch();
This will set up a handler for the route "/"
, which will look for a file called hello.md
in the nodes/
directory.
In Pagenode, a keyword is the file name minus the .md
extension. By definition, a keyword is unique – you can't have two files with the same name.
After the node has been loaded, the route handler will include our template templates/node.html.php
, so let's create it:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title><?= $node->title ?? 'Pagenode' ?></title>
</head>
<body>
<?= $node->body ?>
<p class="foot">
Created at <?= $node->date->format('Y.m.d') ?>
</p>
</body>
</html>
You can now start PHPs built-in Web Server to have a quick look at your page. Issue the following command in the directory where your index.php is located:
php -S localhost:8080
You should now be able to load localhost:8080 in your browser and read your hello.md
file.
In order to make the URL routing work with clean URLs, you have to let your index.php handle all requests.
For Apache, you can place Pagenode's .htacces file in the directory where your index.php is located.
For Nginx you can use the following configuration for your host:
server {
server_name yourdomain.com;
root /var/www/yourdomain;
location ~ /\.git {
deny all;
}
include php-fastcgi.conf;
# Let Pagenode handle all requests
try_files $uri $uri/ /index.php?$query_string;
}
If you don't want to setup clean URLs, you can also route requests via a GET
parameter.
E.g. for URLs like example.com/?path=blog/some-keyword
you can change the dispatch()
call to use the path
GET
parameter:
dispatch($_GET['path']);
Or, a bit cleaner, for URLs like example.com/?blog/some-keyword
use the first $_GET
key:
dispatch(key($_GET));
Up Next: Adding Content »