Schemer

Links
Tech
  • PHP

Schema.org microdata is a great way to embed structured data in your web page, but writing it out can be tedious, and usually involves a lot of copying and pasting. I wanted to alleviate some of that, so I build this library.

Its primary purpose is to provide a couple of “Schemes” that represent full definitions (i.e PostalAddress or LocalBusiness) and take a simple array of data with which then generate all the necessary HTML. Much nicer!

echo AlwaysBlank\Schemer\Scheme\PostalAddress::build([
    ['street', '123 Oak St'],
    ['state', 'OR'],
    ['city', 'Portland'],
    ['zip', '97123'],
    ['pobox', 'P.O. 1234'],
    ['country', 'USA'],
]);

// <span itemscope itemprop="http://schema.org/PostalAddress"><span itemprop="streetAddress">123 Oak St</span><span itemprop="addressRegion">OR</span><span itemprop="addressLocality">Portland</span><span itemprop="postalCode">97123</span><span itemprop="postOfficeBoxNumber">P.O. 1234</span><span itemprop="addressCountry">USA</span></span>

Schemer is also built to be easily extendable: You can add new Properties or Schemes on the fly, as well as quickly compose your own Schemes or kinda-Schemes whenever you need them. Currently it ships with only two Schemes and a limited number of Properties, but that will expand as I need it to expand (or as people submit PRs!).