Download the PHP package nixn/hiccup without Composer

On this page you can find all versions of the php package nixn/hiccup. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package hiccup

hiccup-php

An HTML rendering and templating engine, based on PHP code (strings, arrays, classes and inheritance). It is a (sophisticated) port of Hiccup for Clojure.

Installation

Via composer:

Usage

The library consists of two main parts: the Hiccup class and the Template interface with its counterpart, the abstract class Template_Base.

Hiccup

This is the class which renders HTML from a number of data structures (including Template). It has a single main method: static function html(mixed ...$elements): string (and several helper methods), and it interprets the different elements passed to it as HTML structure(s) (recursively), joins them together and returns the resulting HTML string.

Possible elements (PHP types):

null

A null value renders nothing, it effectively is ignored (equivalent to an empty string as result).

string

A string is taken as the leaf value of an HTML structure, best described as textual tag content. It is automatically escaped, unless you use Hiccup::raw() to protect it; then it is passed as-is to the output string.

(another) scalar or \Stringable value

That includes values like booleans, integers, floats, etc., all of which have a natural string representation, or objects of classes implementing \Stringable but not Template. They are converted to an escaped string too, but without the possibility to be protected by Hiccup::raw() directly. If you want that, you have to convert it yourself, e.g. by calling Hiccup::raw("$my_stringable_object").

Templates

These objects are handled differently. The method (Template::)hiccup(): mixed is called on them, which can return any Hiccup element, which is then rendered recursively. Due to the nature of PHP, which can return only one value from a function, often it will be the result of the call Hiccup::each(), which is an iterable (see below), but it can also be any other element from this list.

iterable (except array)

An iterable is taken as a list of sibling elements. They are rendered behind one another, calling html() recursively on them. An array is explicitely not handled as an iterable, because it is ... (see below).

array

Arrays are the heart of the Hiccup "language", they denote HTML tags and their children and make up the structure of HTML. They start with a string, which is the tag name; optionally followed by an associative array, which is rendered as the attributes of this tag; and finally followed by zero or more child elements, which are rendered as siblings (just like in Hiccup::each() or with an iterable) below this tag in the result.

The tag name can have modifications (suffixes), which are interpreted as attributes, to enable easy and fast declaration of the tag attributes. In detail that are:

For better readability the values (<id>, <class>, <name>, <value> and the tag name itself) can have whitespace after them, but not before (except <name>) and also not in between.

Example:

(The title could not be written into the tag name string, because the value has whitespace!)

In the attributes array the elements have some different value possibilities:

Hiccup has some helper functions to ease templating:

Template

The Template interface is the connection between the rendering and the class based templating. As described above a class which implements Template is a valid Hiccup element and will be called for its Hiccup code for rendering. Through inheritance and composition (usual class operations) it is possible to create the most complex templates, still as easy managable as a class structure, even with more power than with other templating engines, which always try to resemble the class structure in some way. Here it can be used directly (and is demonstrated below).

Template_Base

This abstract class is a helper class to make the template classes a breeze. It has two main functions:

Dynamic Methods

It uses the PHP magic method __call(string $name, array $args): mixed. That means every template class (which derives from Template_Base) can just use a call like $this->content() and if a subclass overrides it, it can deliver that content. If not, null is returned and rendered into nothing.

Namespacing

Every derived template class can be assigned a parent and optional affixes, which is used in the dynamic call: If a parent is set, the call is redirected to it with the affixes appended, so the parent has control over its subtemplates and their calls.

Both is best explained by an example:

HTML5

nixn\hiccup\HTML5 is a pre-defined template class which can be used as a base for HTML5 pages. It contains the basic boilerplate with default but overridable values and can be the base of every generated template in a web page, which has to display HTML content. You may start with just overriding body(): mixed and put your content there, optionally title(): string too, and you are good to go for a basic page.

Bootstrap example

With a really tiny bit more effort we can build the base page for a Bootstrap layout.

And use it:

License

Copyright © 2025 nix https://keybase.io/nixn

Distributed under the MIT license, available in the file LICENSE.

Donations

If you like hiccup-php, please consider dropping some bitcoins to 1nixn9rd4ns8h5mQX3NmUtxwffNZsbDTP.


All versions of hiccup with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
nixn/php-util Version ^1.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package nixn/hiccup contains the following files

Loading the files please wait ....