Download the PHP package mintyphp/template without Composer
On this page you can find all versions of the php package mintyphp/template. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package template
MintyPHP Template
Simple yet powerful Jinja-like templating system for HTML written in PHP.
See: https://www.tqdev.com/2026-jinja-templating-engine-html-php/
Overview
MintyPHP's Template engine provides a simple yet powerful Jinja-like templating system with variable interpolation, control structures, filters, and expression evaluation. Templates are HTML-safe by default with automatic escaping.
Requirements
- PHP 8+
Installation
Add a dependency with Composer:
Usage
BNF Syntax
Operators
Arithmetic Operators
+Addition (also string concatenation)-Subtraction*Multiplication/Division%Modulo
Comparison Operators
==Equal!=Not equal<Less than>Greater than<=Less than or equal>=Greater than or equal
Logical Operators
and,&&Logical ANDor,||Logical ORnotLogical NOT (unary)
Operator Precedence (highest to lowest)
not(unary)*,/,%+,-<,>,<=,>===,!=and,&&or,||
Features
- Variable interpolation with
{{ }}syntax - Control structures with
{% %}syntax (if/elseif/else, for loops) - Template inheritance with
{% extends %}and{% block %} - Template inclusion with
{% include %} - Comments with
{# #}syntax - Expression evaluation with full operator support
- Filters with pipe syntax
| - Builtin filters for common transformations
- Tests with
iskeyword for value checking - Nested data access with dot notation
- HTML escaping by default
- Raw output with
rawfilter - Custom filters and tests
Examples
Example 1: Basic Variable Interpolation
Data (JSON):
Template:
Output:
Example 2: HTML Escaping
Data (JSON):
Template:
Output:
Example 3: Conditional Rendering
Data (JSON):
Template:
Output:
Example 4: If-ElseIf-Else Chain
Data (JSON):
Template:
Output:
Example 5: For Loops with Arrays
Data (JSON):
Template:
Output:
Example 6: For Loops with Key-Value Pairs
Data (JSON):
Template:
Output:
Example 7: Nested For Loops
Data (JSON):
Template:
Output:
Example 8: Nested Data Access
Data (JSON):
Template:
Output:
Example 9: Expressions in Variables
Data (JSON):
Template:
Output:
Example 10: String Concatenation
Data (JSON):
Template:
Output:
Example 11: Complex Conditions
Data (JSON):
Template:
Output:
Example 12: For Loop with Conditionals
Data (JSON):
Template:
Output:
Example 13: Comments
Data (JSON):
Template:
Output:
Example 14: Blog Post List
Data (JSON):
Template:
Output:
Example 15: Dashboard with Statistics
Data (JSON):
Template:
Output:
Template Inheritance
MintyPHP's template engine supports template inheritance through {% extends %} and {% block %} directives,
allowing you to create reusable base templates.
Example: Base Template
base.html:
Example: Child Template
page.html:
Notes:
{% extends %}must be the first non-whitespace element in the child template- Blocks defined in the child completely replace blocks in the parent
- Blocks not overridden use the parent's default content
- Template inheritance requires a template loader function
Template Inclusion
Use {% include %} to insert another template at a specific point.
Example: Including Templates
header.html:
main.html:
Notes:
- Included templates share the same data context as the parent
- Requires a template loader function to be configured
Builtin Filters
MintyPHP includes comprehensive builtin filters for common transformations.
String Filters
lower
Convert to lowercase.
upper
Convert to uppercase.
capitalize
Capitalize first character.
title
Title case (capitalize each word).
trim
Remove leading/trailing whitespace.
truncate(length, end)
Truncate string to length (default 255, default end "...") without breaking words.
replace(old, new, count)
Replace substring occurrences.
split(separator)
Split string into array.
urlencode
URL-encode a string.
reverse
Reverse string or array.
Numeric Filters
abs
Absolute value.
round(precision, method)
Round number (default precision=0, method="common"). Available methods: common, ceil, floor, down, even/banker, odd, awayzero, tozero.
sprintf(format)
Format with sprintf.
filesizeformat(binary)
Format bytes as human-readable size.
Array/Collection Filters
length / count
Get count of items or string length.
first(n)
Get first item or first n items.
last(n)
Get last item or last n items.
join(separator, attribute)
Join array elements with separator.
sum(attribute)
Sum numeric values in array.
Utility Filters
default(value, boolean)
Return default if value is null (or falsy with boolean=true).
attr(name)
Get attribute by name.
debug / d
Pretty-print value as JSON for debugging.
raw
Output unescaped HTML (builtin).
Builtin Tests
Tests allow you to check properties of values using the is keyword in expressions.
Syntax
Available Tests
defined
Check if variable is defined.
undefined
Check if variable is undefined.
null
Check if value is null.
even
Check if number is even.
odd
Check if number is odd.
divisibleby(n)
Check if number is divisible by n.
number
Check if value is numeric.
string
Check if value is a string.
iterable
Check if value can be iterated.
Test Negation
Use is not to negate tests:
Custom Filters
Custom filters can be provided to the Template constructor.
PHP Usage Example:
Custom Tests
Custom tests can be provided as the third argument to the Template constructor.
PHP Usage Example:
Notes
- All output is HTML-escaped by default for security
- Use the
rawfilter to output unescaped HTML:{{ content|raw }} - Whitespace in templates is generally preserved
- Lines containing only whitespace and a
{% %}tag or{# #}comment are removed - Expressions support parentheses for grouping:
{{ (a + b) * c }} - Paths use dot notation for nested access:
{{ user.profile.name }} - For loops can iterate with values only or with key-value pairs
- Comments are completely removed from output and don't affect whitespace
- Builtin filters are available automatically without configuration
- Tests use the
iskeyword:{% if value is defined %}
Template Inheritance Notes
- The
{% extends %}directive must be the first non-whitespace element in a child template - Template inheritance and
{% include %}require a template loader function to be configured - Child block content completely replaces parent block content
- Blocks not overridden in the child will use the parent's default content
- Blocks can be nested, and each can be independently overridden
- Variables, expressions, and all other template features work inside blocks