dtkahl/php-page

3.2.6 2017-01-25 16:01 UTC

README

Latest Stable Version License Build Status

Abandoned! - PHP Page

PHP helper class for building HTML response.

Dependencies

  • PHP >= 5.6.0

Usage

$page = new \Dtkahl\Page\Page;

Functionality

meta data

add meta data:

$page->meta->set('title', 'foobar');

render meta data (ibnside your template):

<?php echo $page->renderMeta() ?>

supported keys:

  • title
  • charset
  • date
  • copyright
  • keywords
  • viewport
  • robots
  • page-topic
  • page-type
  • og:type
  • audience
  • google-site-verification
  • csrf-token
  • twitter:site
  • twitter:card
  • local
  • og:site_name
  • description
  • image
  • url
  • author
  • publisher
  • language
  • (raw)

options

With options you can configure the page:

  • title_pattern : pattern for meta title. Example: %s | foobar.com
$page->options->set('title_pattern', `%s | foobar.com`);

asset managment (JS, CSS)

You can define which files should be loaded.

$page->addJavascript('script'); // ".js" automatically added
$page->addStylesheet('style'); // ".css" automatically added

... and render the includes in your template:

<?php echo $page->renderJavascripts() ?>
<?php echo $page->renderStylesheets() ?>

sections

With sections you have one more way to push information to your view.

Example to pass simple information...

$page->sections->set('foo', 'bar')

In your view you can retrieve the section:

<?php echo $page->sections->get('foo') ?>

areas

Almost like sections, but an area is a collection of multiple items. (Like widgets in a sidebar)

Example:

$page->area('sidebar')->push('bar')

In your view you can iterate over the items of the area:

<?php $page->area('sidebar')->each(function ($widget) {
      echo $widget;
  });
?>

aliases

  • $page->meta($key) does the same like $page->meta->get($key)
  • $page->meta($key, $value) does the same like $page->meta->set($key, $value)
  • $page->option($key) does the same like $page->options->get($key)
  • $page->option($key, $value) does the same like $page->options->set($key, $value)
  • $page->section($key) does the same like $page->sections->get($key)
  • $page->section($key, $value) does the same like $page->sections->set($key, $value)