Giter Club home page Giter Club logo

htmlki's Introduction

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.

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

What we see here is:

  • 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.

[ Full documentation ]

Usage

Available for Composer under proger/htmlki at Packagist.

Standalone:

// 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.

HTMLki imbues HTML with:

  • 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.

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.).

htmlki's People

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.