Manipulate every part of an HTML Page at any time.

v1.2 2017-01-30 15:57 UTC

This package is not auto-updated.

Last update: 2023-11-25 13:18:30 UTC


Packagist License MIT HHVM Tested PHP 7 Supported Build Status Code Climate Test Coverage

A framework agnostic HTML framework that allows you to manipulate every part of an HTML Page at any time.


Add the following to your composer.json file.

    "require": {
        "bootpress/page": "^1.0"

Example Usage


use BootPress\Page\Component as Page;

$page = Page::html();

The Page class implements the Singleton design pattern so that you can call it from anywhere, and still be on the same "Page". You don't have to, but if you would like to enforce a desired url scheme (recommended), then do this:

$page = Page::html(array(
    'dir' => '../', // a root folder where you can keep everything safe and sound
    'base' => '', // this will be enforced now
    'suffix' => '.html', // goes at the end of your urls
)); // You can only do this once

Symfony is our undisputed friend here. This class relies on their HttpFoundation component. You can pass us an instance if you already have one going, or we will create one for you. Check this out:

$page->response->request->query->get('key'); // or ...
$page->post('key'); // ie. a $_POST['key'] with benefits

The $page->response above is the Symfony Response object that you can access directly. You can also call (or set) $page->session, and if you didn't have one before, you do now.

Now that setting up is out of the way ...

// The .ico and .css files will go to your <head>
// The .js file will be at the bottom of your <body>

// To put a <link> before all the others you have set
$page->link('', 'prepend');

// Meta tags are placed at the top of the <head>
$page->meta('name="author" content="name"'); // or ...
$page->meta(array('name'=>'author', 'content'=>'name')); // or ...
$page->link('<meta name="author" content="name">'); // You can spell all these tags out with the link method

// <style> tags are placed right after the <link>'s
$page->style('body { background-color:red; color:black; }'); // or ...
$page->style(array('body { background-color:red; color:black; }')); // or ...
$page->style(array('body' => 'background-color:red; color:black;')); // or ...
$page->style(array('body' => array('background-color:red;', 'color:black;'))); // or ...
$page->link('<style>body { background-color:red; color:black; }</style>');

// <script> tags come immediately after the .js files
$page->script('alert("Hello World");'); // or
$page->link('<script>alert("Hello World");</script>');

// All of these will go into one $(document).ready(function(){...}); at the bottom of your page
$page->jquery('$("button.continue").html("Next Step...");');

Of course, none of that does any good if you don't give us the final HTML to work with:

echo $page->display('<p>Content</p>');

That will return you a nice:

<!doctype html>
<html lang="en">
    <meta charset="utf-8">
    <meta name="author" content="name">
    <link rel="shortcut icon" href="">
    <link rel="stylesheet" href="">
    <link rel="stylesheet" href="">
    <style>body { background-color:red; color:black; }</style>
    <script src=""></script>
    <script>alert("Hello World");</script>
        $("button.continue").html("Next Step...");

To change (or access) the default values that have been set (by anyone), you can:

$page->title = 'Page Title';
$page->description = 'Page description.';
$page->charset = 'UTF-8';
$page->language = 'en-us';

echo '<h1>'.$page->title.'</h1>'; // <h1>Page Title</h1>

Above, you just gave us your <p>Content</p>, and we created the HTML Page around it. You can also give us the entire page, and we'll still put things where they belong:


	<  !doctype html>
<html   >
<HEad>< title>Broken</tit
<META content=" name " name="author">
	</ head>  <body style="color:#333;">
	I'm in the body!</body>
< /html>


That will give you:

<  !doctype html>
<html   >
    <meta charset="UTF-8">
    <meta name="description" content="Page description.">
< title>Broken</tit
<META content=" name " name="author">
    <link rel="shortcut icon" href="">
    <link rel="stylesheet" href="">
    <link rel="stylesheet" href="">
    <style>body { background-color:red; color:black; }</style>
<body style="color:#333;">

	I'm in the body!
    <script src=""></script>
    <script>alert("Hello World");</script>
        $("button.continue").html("Next Step...");

It's a bit screwed up still, but that's how you wanted it. We took nothing out, and only added the parts that were missing with the information you gave us. This class can do as little, or as much as you like. It's all the same to us. Even if you use none of the above, it's still nice to have a central location where an application can create, and work with urls established according to your specs.

$page->enforce('seo-path'); // If the current url was not, it is now.

echo $page->url['path']; // seo-path

if ($page->get('form') == 'submitted') { //
    $eject = $page->url('delete', '', 'form'); //
    $page->eject($page->url('add', $eject, 'payment', 'received')); // go now to
} elseif ($page->get('payment') == 'received') {
    mail($address, 'Thanks for your money!');

That should be a good enough sampling for a README file. We didn't even get to directories, filters, and responses, but it's all there in the source code, fully documented.



The MIT License (MIT). Please see License File for more information.