Download the PHP package bayfrontmedia/veil without Composer
On this page you can find all versions of the php package bayfrontmedia/veil. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download bayfrontmedia/veil
More information about bayfrontmedia/veil
Files in bayfrontmedia/veil
Package veil
Short Description A fast, lightweight, framework-agnostic PHP template engine.
License MIT
Homepage https://github.com/bayfrontmedia/veil
Informations about the package veil
Veil
A fast, lightweight, framework-agnostic PHP template engine.
Although there are some respectable, well-known PHP template engines available, most of them can be extremely complex and include a great deal of customized syntax to learn. In addition, using proprietary libraries to perform simple functions and iterations can introduce unnecessary complexity and overhead, especially since PHP is a templating language in and of itself.
While it may not be suitable for every outlying case, Veil has been created to provide minimal and rapid template language functionality, including template inheritance, in a simple framework-agnostic library.
- License
- Author
- Requirements
- Installation
- Usage
License
This project is open source and available under the MIT License.
Author
Requirements
- PHP
^8.0
(Tested up to8.4
)
Installation
Usage
Start using Veil
Default configuration:
Working with content
Template tags
A variety of template tags can be used with Veil. This allows for functionality such as template inheritance (chaining files), injection of content, and usage of passed parameters.
The following template tags can be used in HTML and view files:
Tag | Function |
---|---|
@use:path/from/base |
Adds contents of another file |
@markdown:path/from/base |
Adds markdown of another file as HTML (see markdown) |
@inject:type |
Injects content (see inject) |
@section:name |
Defines a section to be placed in a view (see sections) |
@place:name |
Places a defined section into the view (see sections) |
?@place:name |
Places an optionally defined section into the view (see sections) |
{{-- Comment —-}} |
Everything inside comment tags will be ignored and removed |
{{parameter.name}} |
Replaced with escaped value from the $data array in dot notation |
{{!parameter.name}} |
Replaced with unescaped (raw) value from the $data array in dot notation |
{{parameter.name||default}} |
Replaced with escaped value from the $data array in dot notation or default value if not existing * |
{{!parameter.name||default}} |
Replaced with unescaped (raw) value from the $data array in dot notation or default value if not existing * |
Note:
The default value can be either a plaintext string, or another key on the
$data
array in dot notation.
Sections
Sections are used to define a block of HTML using the @section
tag,
which is placed in a view using the @place
tag.
Example pages/index
:
Example layouts/default
:
In the examples above, the sections head
and content
are defined in pages/index
,
then placed in layouts/default
.
In addition, an optional end_body
section is placed before the closing body
tag.
Raw PHP
View files can directly access the $data
array in raw PHP.
In fact, any other PHP code can be directly embedded in any view file.
However, this should be kept to simple tasks such as performing loop iterations.
Frequently embedding raw PHP from your view may be a sign you have too much logic within the template.
Public methods
- getBasePath
- setBasePath
- inject
- getHtml
- html
- getView
- view
- minify
- markdown
getBasePath
Description:
Returns base path.
Parameters:
- (None)
Returns:
- (string)
setBasePath
Description:
Sets base path.
Parameters:
$base_path
(string)
Returns:
- (void)
inject
Description:
Add injectable(s) by their respective types.
Default injectable types to use in your templates include:
css
: Wraps content into a CSS<link>
elementjs
: Wraps content into a<script>
elementhead
: Insert content into the<head>
sectionend_body
: Insert content just before the</body>
tag
In addition to the default injectable types, custom types can be added and used.
NOTE: If $content
is an array, all injectables will share the same priority.
Parameters:
$type
(string)$content
(string|array)$priority = 5
(int): Injectables of the same type will be injected in order of priority
Returns:
- (self)
Example:
Using the above example, whenever the @inject:js
template tag appears, it will be replaced with:
getHtml
Description:
Get compiled HTML as a string.
Parameters:
$html
(string)$data = []
(array): Data to pass to HTML$minify = false
(bool): Minify compiled HTML? See minify for more info.
Returns:
- (string)
Throws:
Bayfront\Veil\FileNotFoundException
Example:
html
Description:
Echo compiled HTML.
Parameters:
$html
(string)$data = []
(array): Data to pass to HTML$minify = false
(bool): Minify compiled HTML? See minify for more info.
Returns:
- (void)
Throws:
Bayfront\Veil\FileNotFoundException
Example:
getView
Description:
Get compiled template file as a string.
Parameters:
$file
(string): Path to file from base path, excluding file extension$data = []
(array): Data to pass to view$minify = false
(bool): Minify compiled HTML? See minify for more info.
Returns:
- (string)
Throws:
Bayfront\Veil\FileNotFoundException
Example:
view
Description:
Echo compiled template file.
Parameters:
$file
(string): Path to file from base path, excluding file extension$data = []
(array): Data to pass to view$minify = false
(bool): Minify compiled HTML? See minify for more info.
Returns:
- (void)
Throws:
Bayfront\Veil\FileNotFoundException
Example:
minify
Description:
Minify HTML.
Currently, Veil uses Tiny Html Minifier for this method.
NOTE: In some cases, HTML may not minify correctly, so use with caution. It is recommended you test this with your HTML and views before using in production.
Parameters:
$html
(string)
Returns:
- (string)
Example:
See markdown.
markdown
Description:
Convert Markdown syntax to HTML.
Currently, Veil uses Parsedown for this method.
Parameters:
$markdown
(string)
Returns:
- (string)
Example:
Convert a view file containing markdown to minified HTML:
All versions of veil with dependencies
bayfrontmedia/php-array-helpers Version ^2.0
bayfrontmedia/php-sanitize Version ^2.1
erusev/parsedown Version ^1.7.4
pfaciana/tiny-html-minifier Version *