Library for rendering native php templates

v1.1.1 2022-03-19 20:46 UTC

This package is auto-updated.

Last update: 2024-05-20 01:43:12 UTC


.github/workflows/push.yml Test Coverage Maintainability Latest Stable Version Total Downloads License

PHP library for rendering native php templates with sections, inheritance and helpers.

This library is inspired by aura/view and league/plates. Both have advantages against each other and both are lacking some major features.

Að sýna means to show in Icelandic.


Both libraries are missing a functionality to not register each helper. Syna has the ability to register namespaces where your helpers are placed. Adding the namespace App\ViewHelper would load App\ViewHelper\Date for $view->date().


Syna also provides the ability to use layouts as described by the TwoStepView pattern. Other then extending views from inside a view (suggested by other libraries like league/plates, illuminate/blade etc.) you should define the layout in your controller. The separation of concerns between extending views and wrapping a html snipped into another one is logic that should not be decided from views (e. g. loading the content of a modal dialog or loading a full page with navigation, header and footer).

Named Locators

Extending Views


Like all my libraries: only with composer

$ composer require tflori/syna

Basic usage


use Syna\Factory;
use Syna\HelperLocator;
use Syna\ViewLocator;

$viewLocator = new ViewLocator(__DIR__ . '/resources/views');
$layoutLocator = new ViewLocator(__DIR__ . '/resources/layouts');
$helperLocator = new HelperLocator();

$templates = new Factory($viewLocator, $helperLocator, $layoutLocator);

echo $templates->render('pages/home', [], 'fullPage');


<!DOCTYPE html>
<html lang="en">
        <meta charset="UTF-8">
        <?= $v->fetch('partials/navbar') ?>
        <div id="content">
            <?= $v->section('content') ?>


<?php $v->extends('pageWithTeaser'); ?>

<?php $v->start('teaser') ?>

<img src="teaser.jpg" />

<div class="teaser-content">
    <h2>Title for teaser</h2>
    <p>Lorem ipsum dolor sit amet...</p>

<?php $v->end(); ?>

<div class="card">Lorem ipsum dolor sit amet...</div>
<div class="card">Lorem ipsum dolor sit amet...</div>

<p>what ever...</p>


<div class="teaser">
    <?= $v->section('teaser') ?>

<?= $v->section('content') ?>

Please also have a look at the example for a more concrete example and at the tests for the documented examples.