2017 © Pedro Peláez
 

library htmlki

Seamless templating with the HTML spirit. PHP 5.2+.

image

proger/htmlki

Seamless templating with the HTML spirit. PHP 5.2+.

  • Sunday, March 16, 2014
  • by Proger
  • Repository
  • 1 Watchers
  • 3 Stars
  • 3 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

HTMLki - seamless templating with the HTML spirit

HTMLki takes a non-mainstream approach. Unlike inventing yet another PHP or Mustache it imbues old good HTML with new features - loops, variables, localization, custom tags and more without breaking its original clean form., (*1)

<ul $menu>
  <li "$classes">
    <img $icon src=$icon>
    <a "$url" target=$target>$caption</a>
  </li>
</endul>

What we see here is:, (*2)

  • A loop: <ul> is only output if there's at least one item in $menu
  • An "if": <img> is only output if $icon is non-falsy
  • A bunch of attribute magic: <li "classes"> (<li class="classes">), <a "url"> (<a href="url">)
  • Anti-XSS: $caption is a variable, escaped by default

It has no dependencies and works out of the box in PHP 5.6 and above., (*3)

[ Full documentation ], (*4)

Usage

Available for Composer under proger/htmlki at Packagist., (*5)

Standalone:, (*6)

// Configure your autoloader to load the HTMLki namespace from class/HTMLki/.

echo HTMLki\HTMLki::template(HTMLki\HTMLki::compile('<radio>'));
  //=> <input type="radio">

Features

Because HTMLki is just HTML on steroids, any text editor with HTML/PHP syntax scheme gets highlighting right most of the time., (*7)

HTMLki imbues HTML with:, (*8)

  • XSS protection - output is HTML-escaped by default
  • loops and conditions - like in the above example: <ul $list> and <if $a == 3>
  • attribute magic - automatic expansion of <form file> into <form enctype="multipart/form-data">, <div "span-6"> into <div class="span-6"> and more
  • tag magic
    • shortcuts (<radio> into <input type="radio">)
    • multitags (<thead/tr> into <thead><tr>)
    • singletags (<textarea /> into <textarea></textarea>)
    • and more
  • language lines - simply any text wrapped in double quotes: <b>"Hello!"</b>
  • expressions and variables - like { date('d.m.y') }
  • PHP code - just as you guess: <?='string'?> - short PHP tags expanded automatically so you don't have to care about any particular php.ini settings
  • function-tags - in form of custom tags like <include>
  • input checking - clearly see what the template accepts: $>currentPage@1 int <= $lastPage
  • most constructs can be escaped, such as ""Not a language.", {{ not_an_expr } and $$notAVar
  • this list is not complete - refer to the documentation for all enhancements

The above doesn't require any additional integration code. However, you can tailor HTMLki into a markup ideal for your particular application by adding handlers for specific tags, attributes, etc., (*9)

For example, HTMLki can automatically expand src, href and action attributes into full URLs, or have tags like <errors> that output the list of errors linked to some input field (textarea, selectbox, etc.)., (*10)

The Versions

16/03 2014

dev-master

9999999-dev https://github.com/ProgerXP/HTMLki

Seamless templating with the HTML spirit. PHP 5.2+.

  Sources   Download

SAX-PD

template html