PHPackages                             phpolar/php-templating - 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. phpolar/php-templating

Abandoned → [phpolar/pure-php](/?search=phpolar%2Fpure-php)Library

phpolar/php-templating
======================

Pure PHP Templates

3.1.4(3mo ago)2125↓100%MITPHPPHP &gt;=8.3CI passing

Since Jan 29Pushed 5d agoCompare

[ Source](https://github.com/phpolar/pure-php)[ Packagist](https://packagist.org/packages/phpolar/php-templating)[ RSS](/packages/phpolar-php-templating/feed)WikiDiscussions main Synced today

READMEChangelog (10)Dependencies (6)Versions (28)Used By (0)

 [![Phpolar Logo](phpolar.svg)](https://github.com/phpolar)

Pure PHP
========

[](#pure-php)

Templating that's just PHP. That's it. Seriously.

Support using [pure PHP templates](#pure-php-templates) with automatic XSS mitigation.

[![Coverage Status](https://camo.githubusercontent.com/ca6de6e3030c091e6db52478714f421f1a35d0a04027ce3faf6fd5b67f327862/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f7068706f6c61722f707572652d7068702f62616467652e7376673f6272616e63683d6d61696e)](https://coveralls.io/github/phpolar/pure-php?branch=main) [![Version](https://camo.githubusercontent.com/5959beb4dc4d108de9e3698a7f0f050fafca5019634668f7bb99c2185d8c9421/68747470733a2f2f706f7365722e707567782e6f72672f7068706f6c61722f707572652d7068702f76657273696f6e)](https://packagist.org/packages/phpolar/pure-php) [![PHP Version Require](https://camo.githubusercontent.com/c9af648eed2bda29f64b0f4a9c10e1e9b0de5a30432d132f2af77cb7d0d9dca4/68747470733a2f2f706f7365722e707567782e6f72672f7068706f6c61722f707572652d7068702f726571756972652f706870)](https://packagist.org/packages/phpolar/pure-php) [![Total Downloads](https://camo.githubusercontent.com/0f25d9f81a184c6e8e9d9858fa9e0b157a99e92d3b4103f916ad91c409ef0bd2/68747470733a2f2f706f7365722e707567782e6f72672f7068706f6c61722f707572652d7068702f646f776e6c6f616473)](https://packagist.org/packages/phpolar/pure-php) [![Weekly Check](https://github.com/phpolar/pure-php/actions/workflows/weekly.yml/badge.svg)](https://github.com/phpolar/pure-php/actions/workflows/weekly.yml)

Table of Contents
-----------------

[](#table-of-contents)

1. [Installation](#installation)
2. [Usage](#usage)
3. [Example](#example-1)
4. [API Documentation](#api-documentation)

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

[](#installation)

```
composer require phpolar/pure-php
```

Usage
-----

[](#usage)

```
$page = new Page();
$safeContext = new HtmlSafeContext($page);
$templateEng->render("path/to/template.php", $safeContext);
// or...
echo $templateEng->apply("path/to/template", $safeContext /* optional */);
```

### Template Basename Only

[](#template-basename-only)

```
// or...
echo $templateEng->apply("template", $safeContext /* optional */);
// or...
echo $templateEng->apply("template", $safeContext /* optional */);
```

> The template engine will look for files with .php, .phtml, or .html extensions in `src/templates` directory relative to the current working directory.

Example 1
---------

[](#example-1)

### Pure PHP Templates

[](#pure-php-templates)

```
// template.php or template.phtml
