I’m looking for a way to build plain PHP templates with inheritance. I’ve used phpti before, but it’s not working properly within Slim. It works fine with a simple example, but when I have multiple blocks, it fails miserably. I really don’t want to use Twig.
All I did, was include phpti in index, and use this route:
$app->get('/', function (Request $request, Response $response) {
$response = $this->view->render($response, "/pages/home.php");
return $response;
});
// home.php
<?php include APP_VIEWS . "/template.php"; ?>
<?php startblock('head'); ?>
<link rel="stylesheet" href="/assets/css/layout.css">
<?php endblock('head'); ?>
<?php startblock('content'); ?>
<h3>Some Content</h3>
<?php endblock('content'); ?>
// template.php
<html>
<head>
<?php emptyblock('head'); ?>
</head>
<body>
<h1>Here's the header</h1>
<?php emptyblock('content'); ?>
</body>
</html>`Preformatted text`