PHPackages                             zogjs/zog-php - 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. zogjs/zog-php

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

zogjs/zog-php
=============

Lightweight PHP template engine with hybrid static caching (no eval).

0.1.1(5mo ago)21011MITPHPPHP ^8.1

Since Dec 5Pushed 5mo agoCompare

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

READMEChangelog (1)Dependencies (1)Versions (2)Used By (1)

Zog PHP
=======

[](#zog-php)

Lightweight PHP template engine with hybrid static caching (no `eval`, no `DOMDocument`).

- **GitHub:**
- **Packagist:**
- **Install:** `composer require zogjs/zog-php`

Zog gives you a tiny, framework-agnostic view layer plus an optional static HTML cache in front of it. It compiles your templates to plain PHP files, never uses `eval`, and is designed to play nicely with modern frontend frameworks (Vue, Alpine, Livewire, etc.) by leaving their attributes untouched.

Features
--------

[](#features)

- **DOM-less streaming compiler** – custom HTML parser, no `DOMDocument`, so attributes like `@click`, `:class`, `x-data`, `wire:click`, `hx-get`, etc. are preserved exactly as written.
- **Hybrid static cache** – render a page once, save it as static HTML with a TTL, and serve the static file on future requests.
- **Blade-style directives** – `@section`, `@yield`, `@component`, `@{{ }}`, `@raw()`, `@json()` / `@tojs()`, `@php()`.
- **Attribute-based control flow** – `zp-if`, `zp-else-if`, `zp-else`, `zp-for` on normal HTML elements.
- **Fine-grained opt-out** – `zp-nozog` to disable DOM-level processing in a subtree (useful when embedding another templating system).
- **Safe by default** – escaped output for `@{{ }}`, explicit opt-in to raw HTML and raw PHP.

Requirements
------------

[](#requirements)

- PHP **8.1+** :contentReference\[oaicite:0\]{index=0}

No extra PHP extensions are required; Zog uses only core functions.

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

[](#installation)

### 1. Via Composer (recommended)

[](#1-via-composer-recommended)

```
composer require zogjs/zog-php

Then bootstrap it in your project:

```php
 The directories will be created automatically if they do not exist.

### 2. Manual install (alternative)

[](#2-manual-install-alternative)

If you prefer not to use Composer, you can copy `Zog.php` and `View.php` into your project, keep the `Zog` namespace, and load them via your own autoloader or simple `require` statements.

Everything else in this README works the same way.

Quick Start
-----------

[](#quick-start)

### 1. Simple render

[](#1-simple-render)

**views/hello.php**

```
Hello @{{ $name }}!
Today is @{{ $today }}.
```

**public/index.php**

```
