PHPackages                             mintyphp/template - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. mintyphp/template

ActiveLibrary[Templating &amp; Views](/categories/templating)

mintyphp/template
=================

Simple yet powerful Jinja-like templating system for HTML written in PHP

v4.0.1(4mo ago)212MITPHPPHP &gt;=8.0

Since Jan 4Pushed 4mo agoCompare

[ Source](https://github.com/mintyphp/template)[ Packagist](https://packagist.org/packages/mintyphp/template)[ RSS](/packages/mintyphp-template/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (3)Versions (3)Used By (0)

MintyPHP Template
=================

[](#mintyphp-template)

Simple yet powerful Jinja-like templating system for HTML written in PHP.

See:

Overview
--------

[](#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
------------

[](#requirements)

- PHP 8+

Installation
------------

[](#installation)

Add a dependency with Composer:

```
composer require mintyphp/template
```

Usage
-----

[](#usage)

```
use MintyPHP\Template\Template;

$template = new Template();
echo $template->render('{{hi}}',['hi' => 'Hello world']);
// Outputs: Hello world
```

BNF Syntax
----------

[](#bnf-syntax)

```
        ::= *

         ::=  |  |  |

         ::= any text not matching other patterns

        ::= "{{" ?  ? ? "}}"

         ::=  |  |  |  |

         ::= "{#"  "#}"

         ::= "{%" ? "extends"   ? "%}"

         ::= "{%" ? "include"   ? "%}"

           ::=  *

       ::= "{%" ? "block"   ? "%}"

    ::= "{%" ? "endblock" ? "%}"

        ::=  * * ?

          ::= "{%" ? "if"   ? ? "%}"

      ::= "{%" ? "elseif"   ? ? "%}" *

        ::= "{%" ? "else" ? "%}" *

       ::= "{%" ? "endif" ? "%}"

       ::=  *

         ::= "{%" ? "for"    "in"   ? ? "%}"

        ::=  |  ? "," ?

      ::= "{%" ? "endfor" ? "%}"

      ::=

      ::=  (("or" | "||") )*

     ::=  (("and" | "&&") )*

       ::=  (("is" "not"?) )?

            ::=  ("("  ")")?

        ::=  (("==" | "!=") )*

      ::=  (("" | "=") )*

        ::=  (("+" | "-") )*

  ::=  (("*" | "/" | "%") )*

           ::= "not"  |

         ::=  |  |  | "("  ")"

    ::= ("|" )+

          ::=  ("("  ")")?

     ::=  ("," ? )*

      ::=  |  |

            ::=  ("." )*

      ::= [a-zA-Z_][a-zA-Z0-9_]*

          ::= [0-9]+ ("." [0-9]+)?

          ::= '"' ( | )* '"'

      ::= "\\"

              ::= [ \t\n\r]+

```

Operators
---------

[](#operators)

### Arithmetic Operators

[](#arithmetic-operators)

- `+` Addition (also string concatenation)
- `-` Subtraction
- `*` Multiplication
- `/` Division
- `%` Modulo

### Comparison Operators

[](#comparison-operators)

- `==` Equal
- `!=` Not equal
- `` Greater than
- `=` Greater than or equal

### Logical Operators

[](#logical-operators)

- `and`, `&&` Logical AND
- `or`, `||` Logical OR
- `not` Logical NOT (unary)

### Operator Precedence (highest to lowest)

[](#operator-precedence-highest-to-lowest)

1. `not` (unary)
2. `*`, `/`, `%`
3. `+`, `-`
4. ``, `=`
5. `==`, `!=`
6. `and`, `&&`
7. `or`, `||`

Features
--------

[](#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 `is` keyword for value checking
- **Nested data access** with dot notation
- **HTML escaping** by default
- **Raw output** with `raw` filter
- **Custom filters and tests**

---

Examples
--------

[](#examples)

### Example 1: Basic Variable Interpolation

[](#example-1-basic-variable-interpolation)

**Data (JSON):**

```
{
    "title": "Welcome",
    "username": "Alice",
    "message": "Hello, World!"
}
```

**Template:**

```
>

        {{ title }}

        {{ message }}
        Logged in as: {{ username }}

```

**Output:**

```
>

        Welcome

        Hello, World!
        Logged in as: Alice

```

---

### Example 2: HTML Escaping

[](#example-2-html-escaping)

**Data (JSON):**

```
{
    "user_input": "alert('XSS')",
    "safe_html": "Bold Text"
}
```

**Template:**

```

    User input (escaped): {{ user_input }}
    Raw HTML: {{ safe_html|raw }}

```

**Output:**

```

        User input (escaped):
        &lt;script&gt;alert(&#039;XSS&#039;)&lt;/script&gt;

    Raw HTML: Bold Text

```

---

### Example 3: Conditional Rendering

[](#example-3-conditional-rendering)

**Data (JSON):**

```
{
    "user": {
        "name": "Bob",
        "is_admin": true,
        "age": 25
    }
}
```

**Template:**

```

    {{ user.name }}

    {% if user.is_admin %}
    Administrator
    {% endif %}

    {% if user.age >= 18 %}
    Adult user ({{ user.age }} years old)
    {% else %}
    Minor user ({{ user.age }} years old)
    {% endif %}

```

**Output:**

```

    Bob

    Administrator

    Adult user (25 years old)

```

---

### Example 4: If-ElseIf-Else Chain

[](#example-4-if-elseif-else-chain)

**Data (JSON):**

```
{
    "score": 85
}
```

**Template:**

```

    {% if score >= 90 %}
    Grade: A - Excellent!
    {% elseif score >= 80 %}
    Grade: B - Good Job!
    {% elseif score >= 70 %}
    Grade: C - Fair
    {% elseif score >= 60 %}
    Grade: D - Needs Improvement
    {% else %}
    Grade: F - Failed
    {% endif %}

```

**Output:**

```

    Grade: B - Good Job!

```

---

### Example 5: For Loops with Arrays

[](#example-5-for-loops-with-arrays)

**Data (JSON):**

```
{
    "fruits": ["Apple", "Banana", "Cherry", "Date"]
}
```

**Template:**

```

    {% for fruit in fruits %}
    {{ fruit }}
    {% endfor %}

```

**Output:**

```

    Apple
    Banana
    Cherry
    Date

```

---

### Example 6: For Loops with Key-Value Pairs

[](#example-6-for-loops-with-key-value-pairs)

**Data (JSON):**

```
{
    "products": {
        "laptop": "999.99",
        "mouse": "29.99",
        "keyboard": "79.99"
    }
}
```

**Template:**

```

            Product
            Price

        {% for product, price in products %}

            {{ product }}
            ${{ price }}

        {% endfor %}

```

**Output:**

```

            Product
            Price

            laptop
            $999.99

            mouse
            $29.99

            keyboard
            $79.99

```

---

### Example 7: Nested For Loops

[](#example-7-nested-for-loops)

**Data (JSON):**

```
{
    "grid": [
        [1, 2, 3],
        [4, 5, 6],
        [7, 8, 9]
    ]
}
```

**Template:**

```

    {% for row in grid %}

        {% for cell in row %}
        {{ cell }}
        {% endfor %}

    {% endfor %}

```

**Output:**

```

        1
        2
        3

        4
        5
        6

        7
        8
        9

```

---

### Example 8: Nested Data Access

[](#example-8-nested-data-access)

**Data (JSON):**

```
{
    "company": {
        "name": "Tech Corp",
        "employees": [
            {
                "name": "Alice",
                "position": "Developer",
                "salary": 80000
            },
            {
                "name": "Bob",
                "position": "Designer",
                "salary": 75000
            }
        ]
    }
}
```

**Template:**

```

    {{ company.name }}
    Employees

        {% for employee in company.employees %}

            {{ employee.name }} - {{
                employee.position }} (${{ employee.salary }})

        {% endfor %}

```

**Output:**

```

    Tech Corp
    Employees

            Alice - Developer ($80000)

            Bob - Designer ($75000)

```

---

### Example 9: Expressions in Variables

[](#example-9-expressions-in-variables)

**Data (JSON):**

```
{
    "price": 100,
    "quantity": 3,
    "tax_rate": 0.08
}
```

**Template:**

```

    Price per item: ${{ price }}
    Quantity: {{ quantity }}
    Subtotal: ${{ price * quantity }}
    Tax (8%): ${{ price * quantity * tax_rate }}
    Total: ${{ price * quantity * (1 + tax_rate) }}

```

**Output:**

```

    Price per item: $100
    Quantity: 3
    Subtotal: $300
    Tax (8%): $24
    Total: $324

```

---

### Example 10: String Concatenation

[](#example-10-string-concatenation)

**Data (JSON):**

```
{
    "first_name": "John",
    "last_name": "Doe",
    "title": "Dr."
}
```

**Template:**

```

    {{ title + " " + first_name + " " + last_name }}
    Full name: {{ first_name + " " + last_name }}

```

**Output:**

```

    Dr. John Doe
    Full name: John Doe

```

---

### Example 11: Complex Conditions

[](#example-11-complex-conditions)

**Data (JSON):**

```
{
    "user": {
        "age": 25,
        "is_premium": true,
        "credits": 150
    }
}
```

**Template:**

```

    {% if user.age >= 18 && user.is_premium %}
    ✓ Full access granted
    {% endif %}
    {% if user.credits > 100 || user.is_premium %}
    ✓ Can download premium content
    {% endif %}
    {% if (user.age >= 21 && user.credits > 50) || user.is_premium %}
    ✓ Can access exclusive features
    {% endif %}

```

**Output:**

```

    ✓ Full access granted
    ✓ Can download premium content
    ✓ Can access exclusive features

```

---

### Example 12: For Loop with Conditionals

[](#example-12-for-loop-with-conditionals)

**Data (JSON):**

```
{
    "orders": [
        { "id": 1001, "status": "shipped", "total": 99.99 },
        { "id": 1002, "status": "pending", "total": 149.99 },
        { "id": 1003, "status": "delivered", "total": 79.99 },
        { "id": 1004, "status": "cancelled", "total": 199.99 }
    ]
}
```

**Template:**

```

        Order ID
        Total
        Status

    {% for order in orders %}

        #{{ order.id }}
        ${{ order.total }}

            {% if order.status == "shipped" %}
            🚚 Shipped
            {% elseif order.status == "pending" %}
            ⏳ Pending
            {% elseif order.status == "delivered" %}
            ✓ Delivered
            {% else %}
            ✗ Cancelled
            {% endif %}

    {% endfor %}

```

**Output:**

```

        Order ID
        Total
        Status

        #1001
        $99.99

            🚚 Shipped

        #1002
        $149.99

            ⏳ Pending

        #1003
        $79.99

            ✓ Delivered

        #1004
        $199.99

            ✗ Cancelled

```

---

### Example 13: Comments

[](#example-13-comments)

**Data (JSON):**

```
{
    "username": "Alice",
    "email": "alice@example.com"
}
```

**Template:**

```

    {# This is a comment and won't appear in output #}
    {{ username }}

    {# Multi-line comment
    These can span multiple lines and
    won't be rendered #}
    Email: {{ email }}
    {# TODO: Add phone number field #}

```

**Output:**

```

    Alice

    Email: alice@example.com

```

---

### Example 14: Blog Post List

[](#example-14-blog-post-list)

**Data (JSON):**

```
{
    "blog": {
        "title": "My Tech Blog",
        "posts": [
            {
                "id": 1,
                "title": "Getting Started with PHP",
                "author": "Alice",
                "date": "2024-01-15",
                "excerpt": "Learn the basics of PHP programming...",
                "published": true,
                "views": 1234
            },
            {
                "id": 2,
                "title": "Advanced Template Engines",
                "author": "Bob",
                "date": "2024-01-20",
                "excerpt": "Deep dive into template engine design...",
                "published": true,
                "views": 856
            },
            {
                "id": 3,
                "title": "Upcoming Features",
                "author": "Alice",
                "date": "2024-02-01",
                "excerpt": "What's coming next...",
                "published": false,
                "views": 0
            }
        ]
    }
}
```

**Template:**

```
>

        {{ blog.title }}

            {{ blog.title }}

            {% for post in blog.posts %} {% if post.published %}

                {{ post.title }}

                    By {{ post.author }} on {{ post.date }}
                    {% if post.views > 1000 %}
                    🔥 Popular
                    {% endif %}

                {{ post.excerpt }}
                Read more...

            {% endif %} {% endfor %}

```

**Output:**

```
>

        My Tech Blog

            My Tech Blog

                Getting Started with PHP

                    By Alice on 2024-01-15
                    🔥 Popular

                Learn the basics of PHP programming...
                Read more...

                Advanced Template Engines

                    By Bob on 2024-01-20

                Deep dive into template engine design...
                Read more...

```

---

### Example 15: Dashboard with Statistics

[](#example-15-dashboard-with-statistics)

**Data (JSON):**

```
{
    "dashboard": {
        "user": "Admin",
        "stats": {
            "total_users": 1523,
            "active_users": 892,
            "total_revenue": 45678.90,
            "pending_orders": 23
        },
        "recent_activities": [
            {
                "user": "Alice",
                "action": "registered",
                "time": "2 minutes ago"
            },
            {
                "user": "Bob",
                "action": "made a purchase",
                "time": "5 minutes ago"
            },
            {
                "user": "Charlie",
                "action": "updated profile",
                "time": "10 minutes ago"
            }
        ]
    }
}
```

**Template:**

```
>

        Admin Dashboard

        Welcome, {{ dashboard.user }}

                Total Users
                {{ dashboard.stats.total_users }}

                Active Users
                {{ dashboard.stats.active_users }}
                {{ dashboard.stats.active_users * 100 /
                    dashboard.stats.total_users }}% active

                Revenue
                ${{ dashboard.stats.total_revenue }}

                Pending Orders
                {{ dashboard.stats.pending_orders }}

            Recent Activity

                {% for activity in dashboard.recent_activities %}

                    {{ activity.user }} {{ activity.action }}
                    {{ activity.time }}

                {% endfor %}

```

**Output:**

```
>

        Admin Dashboard

        Welcome, Admin

                Total Users
                1523

                Active Users
                892
                58.568611293499% active

                Revenue
                $45678.9

                Pending Orders
                23

            Recent Activity

                    Alice registered
                    2 minutes ago

                    Bob made a purchase
                    5 minutes ago

                    Charlie updated profile
                    10 minutes ago

```

---

Template Inheritance
--------------------

[](#template-inheritance)

MintyPHP's template engine supports template inheritance through `{% extends %}` and `{% block %}` directives, allowing you to create reusable base templates.

### Example: Base Template

[](#example-base-template)

**base.html:**

```
>

        {% block title %}Default Title{% endblock %}
        {% block head %}{% endblock %}

            My Website

            {% block content %}
            Default content
            {% endblock %}

            &copy; 2026 My Website

```

### Example: Child Template

[](#example-child-template)

**page.html:**

```
{% extends "base.html" %}

{% block title %}Welcome Page{% endblock %}

{% block head %}

    .highlight { color: blue; }

{% endblock %}

{% block content %}
Welcome!
This replaces the default content.
{% endblock %}
```

**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
------------------

[](#template-inclusion)

Use `{% include %}` to insert another template at a specific point.

### Example: Including Templates

[](#example-including-templates)

**header.html:**

```

    {{ site_name }}

```

**main.html:**

```
{% include "header.html" %}

    {{ content }}

```

**Notes:**

- Included templates share the same data context as the parent
- Requires a template loader function to be configured

---

Builtin Filters
---------------

[](#builtin-filters)

MintyPHP includes comprehensive builtin filters for common transformations.

### String Filters

[](#string-filters)

#### `lower`

[](#lower)

Convert to lowercase.

```
{{ "HELLO"|lower }} = hello

```

#### `upper`

[](#upper)

Convert to uppercase.

```
{{ "hello"|upper }} = HELLO

```

#### `capitalize`

[](#capitalize)

Capitalize first character.

```
{{ "hello world"|capitalize }} = Hello world

```

#### `title`

[](#title)

Title case (capitalize each word).

```
{{ "hello world"|title }} = Hello World

```

#### `trim`

[](#trim)

Remove leading/trailing whitespace.

```
{{ "  hello  "|trim }} = hello

```

#### `truncate(length, end)`

[](#truncatelength-end)

Truncate string to length (default 255, default end "...") without breaking words.

```
{{ "Hello World"|truncate(8) }} = Hello...
{{ "Hello World"|truncate(10, "..") }} = Hello..

```

#### `replace(old, new, count)`

[](#replaceold-new-count)

Replace substring occurrences.

```
{{ "Hello World"|replace("Hello", "Goodbye") }} = Goodbye World
{{ "aaaaargh"|replace("a", "d'oh, ", 2) }} = d'oh, d'oh, aaargh

```

#### `split(separator)`

[](#splitseparator)

Split string into array.

```
{{ "1,2,3"|split(",")|join("|") }} = 1|2|3
{{ "123"|split()|join("|") }} = 1|2|3

```

#### `urlencode`

[](#urlencode)

URL-encode a string.

```
{{ "hello world"|urlencode }} = hello+world

```

#### `reverse`

[](#reverse)

Reverse string or array.

```
{{ "hello"|reverse }} = olleh
{{ [1,2,3]|reverse|join(",") }} = 3,2,1

```

### Numeric Filters

[](#numeric-filters)

#### `abs`

[](#abs)

Absolute value.

```
{{ -42|abs }} = 42

```

#### `round(precision, method)`

[](#roundprecision-method)

Round number (default precision=0, method="common"). Available methods: common, ceil, floor, down, even/banker, odd, awayzero, tozero.

```
{{ 42.55|round }} = 43
{{ 42.55|round(1, "floor") }} = 42.5
{{ 2.5|round(0, "even") }} = 2

```

#### `sprintf(format)`

[](#sprintfformat)

Format with sprintf.

```
{{ 3.14159|sprintf("%.2f") }} = 3.14
{{ 42|sprintf("%05d") }} = 00042

```

#### `filesizeformat(binary)`

[](#filesizeformatbinary)

Format bytes as human-readable size.

```
{{ 13000|filesizeformat }} = 13.0 kB
{{ 1024|filesizeformat(true) }} = 1.0 KiB
{{ 1500000|filesizeformat }} = 1.5 MB

```

### Array/Collection Filters

[](#arraycollection-filters)

#### `length` / `count`

[](#length--count)

Get count of items or string length.

```
{{ [1,2,3]|length }} = 3
{{ "hello"|length }} = 5

```

#### `first(n)`

[](#firstn)

Get first item or first n items.

```
{{ [1,2,3,4]|first }} = 1
{{ [1,2,3,4]|first(2) }} = [1,2]

```

#### `last(n)`

[](#lastn)

Get last item or last n items.

```
{{ [1,2,3,4]|last }} = 4
{{ [1,2,3,4]|last(2) }} = [3,4]

```

#### `join(separator, attribute)`

[](#joinseparator-attribute)

Join array elements with separator.

```
{{ [1,2,3]|join("|") }} = 1|2|3
{{ users|join(", ", "username") }} = alice, bob, charlie

```

#### `sum(attribute)`

[](#sumattribute)

Sum numeric values in array.

```
{{ [1,2,3]|sum }} = 6
{{ items|sum("price") }} = 150.50

```

### Utility Filters

[](#utility-filters)

#### `default(value, boolean)`

[](#defaultvalue-boolean)

Return default if value is null (or falsy with boolean=true).

```
{{ missing_var|default("N/A") }} = N/A
{{ ""|default("empty", true) }} = empty
{{ 0|default("zero", true) }} = zero

```

#### `attr(name)`

[](#attrname)

Get attribute by name.

```
{{ user|attr("email") }} = user@example.com

```

#### `debug` / `d`

[](#debug--d)

Pretty-print value as JSON for debugging.

```
{{ user|debug }} = {"name":"Alice","email":"alice@example.com"}

```

#### `raw`

[](#raw)

Output unescaped HTML (builtin).

```
{{ "Bold"|raw }} = Bold

```

---

Builtin Tests
-------------

[](#builtin-tests)

Tests allow you to check properties of values using the `is` keyword in expressions.

### Syntax

[](#syntax)

```
{% if variable is testname %}
{% if variable is not testname %}
{% if variable is testname(arg) %}

```

### Available Tests

[](#available-tests)

#### `defined`

[](#defined)

Check if variable is defined.

```
{% if user is defined %}
    User exists: {{ user }}
{% endif %}

```

#### `undefined`

[](#undefined)

Check if variable is undefined.

```
{% if missing is undefined %}
    Variable not defined
{% endif %}

```

#### `null`

[](#null)

Check if value is null.

```
{% if value is null %}
    Value is null
{% endif %}

```

#### `even`

[](#even)

Check if number is even.

```
{% if count is even %}
    Count is even
{% endif %}

```

#### `odd`

[](#odd)

Check if number is odd.

```
{% if count is odd %}
    Count is odd
{% endif %}

```

#### `divisibleby(n)`

[](#divisiblebyn)

Check if number is divisible by n.

```
{% if total is divisibleby(3) %}
    Divisible by 3
{% endif %}

```

#### `number`

[](#number)

Check if value is numeric.

```
{% if value is number %}
    {{ value }} is a number
{% endif %}

```

#### `string`

[](#string)

Check if value is a string.

```
{% if name is string %}
    {{ name }} is a string
{% endif %}

```

#### `iterable`

[](#iterable)

Check if value can be iterated.

```
{% if items is iterable %}
    {% for item in items %}
        {{ item }}
    {% endfor %}
{% endif %}

```

### Test Negation

[](#test-negation)

Use `is not` to negate tests:

```
{% if value is not null %}
    Value exists
{% endif %}

```

---

Custom Filters
--------------

[](#custom-filters)

Custom filters can be provided to the Template constructor.

**PHP Usage Example:**

```
$data = ['name' => 'john doe', 'date' => 'May 13, 1980'];

$filters = [
    'upper' => 'strtoupper',
    'capitalize' => 'ucfirst',
    'dateFormat' => fn($date, $format) => date($format, strtotime($date))
];

$template = new Template(null, $filters);
$html = $template->render(
    'Hello {{ name|upper }}, date: {{ date|dateFormat("Y-m-d") }}',
    $data
);
// Output: Hello JOHN DOE, date: 1980-05-13
```

---

Custom Tests
------------

[](#custom-tests)

Custom tests can be provided as the third argument to the Template constructor.

**PHP Usage Example:**

```
$data = ['age' => 21];

$tests = [
    'adult' => fn($age) => is_numeric($age) && $age >= 18
];

$template = new Template(null, null, $tests);
$html = $template->render(
    '{% if age is adult %}You are an adult{% else %}You are a minor{% endif %}',
    $data
);
// Output: Adult
```

---

Notes
-----

[](#notes)

- All output is **HTML-escaped by default** for security
- Use the `raw` filter 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 `is` keyword: `{% if value is defined %}`

### Template Inheritance Notes

[](#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

### Configuration Example

[](#configuration-example)

```
// Configure template loader for extends/include support
$templateLoader = function(string $name): ?string {
    $path = __DIR__ . '/templates/' . $name;
    return file_exists($path) ? file_get_contents($path) : null;
};

$template = new Template($templateLoader);
$result = $template->render($templateContent, $data);
```

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance75

Regular maintenance activity

Popularity10

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

134d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/eb92d699fb8e724c9a9091ee7182737ffdb5e392a8e137391d102aa8fda8de7b?d=identicon)[mevdschee](/maintainers/mevdschee)

---

Top Contributors

[![mevdschee](https://avatars.githubusercontent.com/u/1288217?v=4)](https://github.com/mevdschee "mevdschee (30 commits)")

---

Tags

jinja2templates-htmltemplating-enginetemplating-language

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Rector

Type Coverage Yes

### Embed Badge

![Health badge](/badges/mintyphp-template/health.svg)

```
[![Health](https://phpackages.com/badges/mintyphp-template/health.svg)](https://phpackages.com/packages/mintyphp-template)
```

###  Alternatives

[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[whitecube/nova-flexible-content

Flexible Content &amp; Repeater Fields for Laravel Nova.

8053.0M25](/packages/whitecube-nova-flexible-content)[mopa/bootstrap-bundle

Easy integration of twitters bootstrap into symfony2

7042.9M33](/packages/mopa-bootstrap-bundle)[limenius/react-bundle

Client and Server-side react rendering in a Symfony Bundle

3871.2M](/packages/limenius-react-bundle)[nicmart/string-template

StringTemplate is a very simple string template engine for php. I've written it to have a thing like sprintf, but with named and nested substutions.

2101.7M30](/packages/nicmart-string-template)[symfony/ux-icons

Renders local and remote SVG icons in your Twig templates.

555.8M69](/packages/symfony-ux-icons)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
