Skip to content

evilncrazy/superb-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 

Repository files navigation

superb-php

Generate nicely formatted HTML using PHP.

include('superb.php');

echo
Sp::html(
   Sp::head(
      Sp::comment('Load the CSS file'),
      Sp::css('style.css')
   ),
   Sp::body(
      Sp::div(array('class' => 'container'),
         Sp::h1('Hi there!'),
         Sp::t('span .alert', 'This is ', Sp::b('superb'), '!')
      )
   )
);
<html>
  <head>
    <!-- Load the CSS file -->
    <link rel="stylesheet" type="text/css" href="style.css" />
  </head>
  <body>
    <div class="container">
      <h1>Hi there!</h1>
      <span class="alert">This is <b>superb</b>!</span>
    </div>
  </body>
</html>

Basic Usage

Grab superb.php and include it into your PHP file. Anything in the form of Sp::name( ... ) will return a tag, with any markup inside the brackets attached as children of this tag.

What can go in the brackets?

  • string: A string simply corrosponds to plain text in the content of the tag
  • array: An array of attribute-value pairs
  • function: The function is called with a new Sp instance as the parameter. Any markup generated by this Sp instance will be attached to the tag.

Remember to echo the markup, as they are returned as a string. Enjoy!

Function Parameters

If a function is given as a parameter, you'll be given a Sp instance to generate markup, like so:

Sp::ul(function($sp) {
   foreach(array('A', 'B', 'C') as $char) {
      $sp->li($char);
   }
});
<ul>
   <li>A</li>
   <li>B</li>
   <li>C</li>
</ul>

This allows you to write logic without breaking the flow of markup.

Aliases

There are special Superb tags called aliases that help generate common tags. For instance, Sp::css('style.css') generates <link rel="stylesheet" type="text/css" href="style.css">

About

Generate nicely formatted HTML using PHP.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages