2017 © Pedro Peláez
 

library layout

Provides a wrapper to render HTML layout with doctype, meta, styles, scripts, etc

image

pyrech/layout

Provides a wrapper to render HTML layout with doctype, meta, styles, scripts, etc

  • Friday, December 20, 2013
  • by pyrech
  • Repository
  • 1 Watchers
  • 0 Stars
  • 15 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 7 % Grown

The README.md

Layout-PHP

Don't handle the HTML doctype, meta, title, style, script, etc yourself, use Pyrech\Layout., (*1)

Layout is a PHP class that wrap and render an HTML Layout. You can customize the doctype, meta, stylesheet, scripts, etc., (*2)

The class can be used in two ways. You can either specify your settings in the render method or add each element in head section in the order you want., (*3)

$content = '<h1>Hello World</h1>';

$layout = \Pyrech\Layout::getInstance(); // Or new \Pyrech\Layout();

$layout->setDoctype(\Pyrech\Layout::DOCTYPE_HTML5)
       ->addMeta('charset', 'utf-8')
       ->addTitle('My wonderful title')
       ->addMeta('description', 'Description of your page')
       ->addMeta('robot', 'index')
       ->addMeta('http-equiv:refresh', '60') // If the key attribute is not 'name', prefix the value by the attribute then ':''
       ->addIcon('/favicon.png', 'png')
       ->addIcon('/favicon.ico', 'ico')
       ->addStyle('/my-stylesheet.css') // Default media is 'all'
       ->addStyle('/print.css', 'print')
       ->addScript('/my-javascript.js', \Pyrech\Layout::SCRIPT_DEFER)
       ->addScript('alert("Hello World!");', \Pyrech\Layout::SCRIPT_INTERNAL)
       ->addBodyClass(array('some-class', 'another-class')); // Array of classes or a string with several classes

echo $layout->render($content);

Second way (via render method):

$content = '<h1>Hello World</h1>';

$layout = \Pyrech\Layout::getInstance(); // Or new \Pyrech\Layout();

$opts = array('doctype' => \Pyrech\Layout::DOCTYPE_HTML5,
              'meta'    => array('charset'            => 'utf-8',
                                 'description'        => 'Description of your page',
                                 'robot'              => 'index',
                                 'http-equiv:refresh' => '60'), // If the attribute is not name, prefix the value by the attribute then ':'
              'title'   => 'My wonderful title',
              'icon'    => array('/favicon.png' => 'png',
                                 '/favicon.ico' => 'ico'),
              'styles'  => array('/my-stylesheet.css', // Default media is 'all'
                                 '/print.css' => 'print'),
              'scripts' => array('/my-javascript.js', // Defer can be setted for one script with the \Pyrech\Layout::SCRIPT_DEFER option
                                 'alert("Hello World!");' => \Pyrech\Layout::SCRIPT_INTERNAL),
              'defer'   => true, // Defer can be setted for all scripts
              'class'   => array('some-class', 'another-class')); // Array of classes or a string with several classes

echo $layout->render($content, $opts);

Custom elements

If you want to insert a custom element in the head part, you must use the first way (see above) and call the addElement method :, (*4)

$layout->addElement('<!--Your html comment-->');

Pyrech\Layout can be implemented in any PHP framework or can be used in a simple structure. Available via composer : pyrech/layout, (*5)

The Versions

20/12 2013

dev-master

9999999-dev http://github.com/Pyrech/Layout-PHP

Provides a wrapper to render HTML layout with doctype, meta, styles, scripts, etc

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

skeleton html layout doctype