Simple PHP page templates and rendering
PHP HTML
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src
templates
.gitignore
README.md
composer.json
composer.lock

README.md

Asset pipeline

The asset pipeline is designed so that you include all assets on every page. There is no automation for including multiple assets together.

Using

Create a new folder templates\ and create templates\header.php and templates\footer.php optionally (or else the framework will use the default supplied templates).

// inc/global.php

use \Pages\PageRenderer;
use \Openclerk\Router;

PageRenderer::addTemplatesLocation(__DIR__ . "/../templates");
PageRenderer::addStylesheet(Router::urlFor("css/default.css"));
PageRenderer::addJavascript(Router::urlFor("js/default.js"));
<?php
// templates/index.php

if ($user) {
  echo "<h2>Logged in successfully as $user</h2>";
} else {
  echo "<h2>Could not log in</a>";
}
?>
// site/index.php

use \Pages\PageRenderer;

$user = get_user();

PageRenderer::header(array("title" => "My page title"));
PageRenderer::requireTemplate("index", array('user' => $user));
PageRenderer::footer();

HAML

You can also define templates with HAML syntax:

/ templates/index.haml

- if($user)
  %h2 Logged in successfully as #{$user}
- else
  %h2 Could not log in

!= link_to(url_for("index"), "Back home")

Events

A number of events are triggered by the library, and can be captured for metrics:

  • pages_header_start, pages_header_end
  • pages_footer_start, pages_footer_end
  • pages_template_start, pages_template_end