Download the PHP package maxonfjvipon/phtml without Composer
On this page you can find all versions of the php package maxonfjvipon/phtml. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download maxonfjvipon/phtml
More information about maxonfjvipon/phtml
Files in maxonfjvipon/phtml
Package phtml
Short Description Pure object-oriented HTML construction templating library with functional interface
License MIT
Informations about the package phtml
phtml
phtml is pure object-oriented HTML construction templating library for PHP with functional interface, inspired by JavaTags and ScalaTags.
This fragment:
will be turned into this html:
Getting started:
Requirements
- PHP >= 8.0
Installation
Examples
basic:
Library provides all html tags as functions with only one exception - <var></var>. PHP does not allow you to create function named var since this word is reserved. So to create <var></var> tag use _var function
(if you know more elegant way to handle this <var></var> - please create an issue)
This code
will render to you this html:
Attributes:
To add attributes to your tag you should use attr function. Function accepts an array with arguments.
Array may has 'key' => 'value' and just 'value' elements:
Attributes will be rendered only if they are at the first place. Other attributes on other places will be ignored.
Library provides helper class Maxonfjvipon\Phtml\at that contains all existed html attributes as consts.
You can use it in this way:
Note!
at::class will return you \Maxonfjvipon\Phtml\at instead of expected 'class' (since ::class is reserved by PHP)
(if it's possible to override this ::class and you know how to do it - please create an issue)
To get 'class' string from at you can do at::_class or at::$class. Or you can just write it manually
Helpers:
Custom tags
You can create your custom tags using 2 helper functions: paired and unpaired:
If you want to add many tags (for example from array) you can use tags function:
Strings, Tags and Texts
Library is based on Maxonfjvipon\ElegantElephant\Txt class from ElegantElephant.
So besides attributes every paired tag can accept other tags, strings and Texts.
This tag:
will be turned into:
Import
If you want to use all available tags and functions you have to add this import.
(if you know how to make this whole import shorter - please create an issue)
Keep in mind that some tag functions have the same name as built in php functions (like \header(), \time(), etc).
So make sure that you have imported these functions before using them.
Contribution
Fork repository, make changes, send a pull request. To avoid frustration, before sending your pull request please run:
And make sure you have no errors.