A faster, safer templating library for PHP

Related tags

Templating brainy

Build Status Latest Stable Version Project Status Total Downloads License



Brainy is a replacement for the popular Smarty templating language. It is a fork from the Smarty 3 trunk.

Brainy is still very new and it's likely that you will encounter some issues. Please report any problems that you encounter.

Why Brainy?

  • Brainy generates clean and fast code by default.
  • Brainy has security defaults that align better with best practices.
  • Brainy does not include features that are infrequently used and increase code bloat.

Because Brainy is a fork of Smarty 3, it shares much of the same syntax and features while eliminating dangerous footguns and making it hard to write bad code.

Getting Started

Check out the Getting Started page on the wiki.

Minimum Requirements

  • PHP 5.4+ or HHVM 3.7+
  • mbstring PHP extension

The mbstring extension is required in order to properly support Unicode in templates and user-provided content. Brainy 3 cannot be run in a mode that does not handle Unicode properly.

Contributing to Brainy

For information on how to set up a local dev environment and run the tests, see the wiki page on Hacking on Brainy.

Where is Brainy headed?

See the project roadmap for information on upcoming releases.

Requested Contributions

If you're interested in helping out, pull requests for the following tasks will be warmly welcomed:

  • Convert all non-public methods to use camel case.
  • Add proper PHPDoc annotations to all functions and methods.
  • Refactoring:
    • Eliminate dead code
    • @ error suppression
    • Increase code coverage
    • etc.
  • Help identify and resolve potential security issues, or find ways to help developers avoid security issues.
  • Performance optimization of generated code

At the time of writing, the project has approximately 68% line coverage.


Need to contact us directly? Email [email protected] and be sure to include the name of this project in the subject.

Copyright and License

Copyright 2014-2015 Box, Inc. All rights reserved.

Copyright 2002 – 2014 New Digital Group, Inc.

This library is licensed under the GNU Lesser Public License. A copy of the license should have been provided.

  • Windows support

    Windows support

    You recommend dropping the constant DIRECTORY_SEPARATOR and always use a forward slash. The code will be easier to read and the library will work on any system, including Windows. It currently fails on Windows because it tried to remove compiled template files without escaping the backslash, thus not forming correct paths.

    P.S. The quick start guide is outdated. It took me a while to find out "new Box\Brainy\Brainy()".

    opened by filerun 14
  • update logo; add logo to README

    update logo; add logo to README

    and crushed the PNG

    opened by cvan 7
  • Ternary operator pls

    Ternary operator pls

    It would be really darn cool if the ternary operator was a thing.

    Right now:

    {if $condition} 
        {$var = $true_option}   
        {$var = $false_option}  

    Super premium: {$var = $condition ? $true_option : $false_option}

    opened by knewkirk 4
  • Update README.md

    Update README.md

    Add version, download and license badges.

    opened by chriseling 2
  • Add script to fail tests if make is not run

    Add script to fail tests if make is not run

    This will hopefully prevent an accidental change to one of the parsers without make getting run.

    opened by mattbasta 2
  • 3.1.0


    opened by vctrshn 2
  • 4.0.0 Roadmap

    4.0.0 Roadmap

    Please update this issue with more.


    • Delete the html_* plugins for good, because they're scary
    • Delete the count_* plugins, because they're mostly unused
    • Delete the strip_tags plugin, since it's most likely not safe
    • Delete all plugins banned in strict mode
    • Delete the following plugins, because they violate web best practices:
      • capitalize: Use text-transform in CSS instead.
      • truncate: Use overflow and text-overflow in CSS instead.
      • date_format: Does not support proper localization, out of scope of Brainy.
    • Remove the make_timestamp and escape_special_chars shared plugins, as they're only depended on by the plugins being removed above.
    • Remove $smarty->template, which is banned in strict mode.
    • Remove syntax features banned by strict mode.
    • Remove support for built-in functions with side effects that are banned in strict mode: reset(), current(), etc.
    • Remove SmartyBC.
    • Remove the inline param from {include}.
    • {* set stricter *} that requires all included templates to be strict


    • AST-based parser and compiler
    • Make it impossible to {include} or fetch a file outside of one of the recognized template directories.
    • Mode that reports which assigned variables were not accessed
      • API should be similar to fetchedTemplate() overridable method
      • Should be enabled with a static flag
      • May be possible to implement by making the scope array inside TemplateData be an object implementing PHP's ArrayAccess interface with zero overhead while mode is off (no new code branches)
    • Make buildFilepath not be insane.


    • 80% code coverage
    • ~100% code coverage for bundled plugins
    • Cut compilation times by 25%
    • Reduce IO-related PHP calls (filemtime, getcwd, etc.) by 25%
    opened by mattbasta 11
  • 3.2.0(Mar 19, 2016)

    Fixed an issue where if changes were made to a source template, making its timestamp out of sync with the timestamp stored as its dependency, the compiled template would fail to decode properly and throw an exception.

    Source code(tar.gz)
    Source code(zip)
  • 3.1.1(Feb 18, 2016)

  • 3.1.0(Feb 17, 2016)

    Changed usage of the constants SMARTY_DIR and SMARTY_PLUGINS_DIR to BRAINY_DIR and BRAINY_PLUGINS_DIR. This should be a minor change, since these constants should not be used by anyone else.

    Also fixed a warning on Windows caused by unlinking a file that did not exist.

    Source code(tar.gz)
    Source code(zip)
  • 3.0.0(Dec 17, 2015)

    The final 3.0.0 release! See the changelog for full information on what's changed.

    Notable Changes

    • Fully namespaced under \Box\Brainy
    • Substantially faster performance than Brainy 2 and Smarty 3.1 (tested with brain-bench). Oodles of performance optimizations.
    • Better error messages
    • Removed lots of cruft
    • Fixed weird syntax, like using negative numbers in modifiers: {$foo|bar:(-1)} -> {$foo|bar:-1}
    • More concise generated code
    • Support for dynamic values passed to {extends}
    Source code(tar.gz)
    Source code(zip)
  • 2.1.3(Nov 9, 2015)

  • 2.1.2(Nov 2, 2015)

  • 2.1.1(Aug 12, 2015)

    This release rolls up the changes from 2.0.2 onto 2.1.

    • Fix for strict mode being too strict
    • Changes to whitespace rules to be more aggressive
    Source code(tar.gz)
    Source code(zip)
  • 2.0.2(Aug 12, 2015)

    This release fixes a number of problems with 2.0.

    • Fixes issues with strict mode being too strict
    • Changes whitespace rules to avoid removing too much whitespace
    • Fixes double backslash bug inside {literal}
    Source code(tar.gz)
    Source code(zip)
  • 2.1.0(Aug 4, 2015)

  • 2.0.0(Apr 23, 2015)

    Brainy 2.0 offers a whole suite of new security features, and contains heavily-refactored code. Improvements in this release remove many potentially unsafe or otherwise unmaintained features to help pare the project to its fundamental components.

    • Strict Mode is now available!
    • New {load} and {store} functions to help eliminate security risk.
    • Better security defaults, like enforce_expression_modifier.
    • Fixes for whitespace stripping inside {strip}
    • Performance enhancements
    • Lots of code cleanup, refactoring, and removal of unused or broken features.

    You can see the full changelog here: https://github.com/box/brainy/wiki/Brainy-2.0-Changelog

    Plans for upcoming releases:

    • Namespacing and exclusive use of Composer's autoloader
    • Giving classes sane names
    • Removal of SmartyBC
    Source code(tar.gz)
    Source code(zip)
  • 1.0.0(Jan 15, 2015)

Box, Inc.
Standalone Skeltch templating engine for PHP

SkeltchGo is a standalone version of Glowie Skeltch templating engine for PHP, intented to use from outside the framework.

glowie 1 Nov 5, 2021
The Templating component provides all the tools needed to build any kind of template system.

Templating Component The Templating component provides all the tools needed to build any kind of template system. It provides an infrastructure to loa

Symfony 983 Nov 10, 2021
SwitchBlade: Custom Directives for the Laravel Blade templating engine

SwitchBlade: Custom Directives for the Laravel Blade templating engine

Awkward Ideas 9 Sep 2, 2021
PHP template engine for native PHP templates

FOIL PHP template engine, for PHP templates. Foil brings all the flexibility and power of modern template engines to native PHP templates. Write simpl

Foil PHP 163 Nov 20, 2021
Twig, the flexible, fast, and secure template language for PHP

Twig, the flexible, fast, and secure template language for PHP Twig is a template language for PHP, released under the new BSD license (code and docum

Twig 7.3k Nov 24, 2021
A Mustache implementation in PHP.

Mustache.php A Mustache implementation in PHP. Usage A quick example: <?php $m = new Mustache_Engine(array('entity_flags' => ENT_QUOTES)); echo $m->re

Justin Hileman 3.1k Nov 17, 2021
Smarty is a template engine for PHP, facilitating the separation of presentation (HTML/CSS) from application logic.

Smarty 3 template engine smarty.net Documentation For documentation see www.smarty.net/docs/en/ Requirements Smarty can be run with PHP 5.2 to PHP 7.4

Smarty PHP Template Engine 1.9k Nov 23, 2021
Native PHP template system

Plates Plates is a native PHP template system that's fast, easy to use and easy to extend. It's inspired by the excellent Twig template engine and str

The League of Extraordinary Packages 1.3k Nov 19, 2021
☕ Latte: the intuitive and fast template engine for those who want the most secure PHP sites.

Latte: amazing template engine for PHP Introduction Latte is a template engine for PHP which eases your work and ensures the output is protected again

Nette Foundation 731 Nov 27, 2021
Multi target HAML (HAML for PHP, Twig, )

Multi target HAML MtHaml is a PHP implementation of the HAML language which can target multiple languages. Currently supported targets are PHP and Twi

Arnaud Le Blanc 362 Aug 5, 2021
PHP Template Attribute Language — template engine for XSS-proof well-formed XHTML and HTML5 pages

PHPTAL - Template Attribute Language for PHP Requirements If you want to use the builtin internationalisation system (I18N), the php-gettext extension

PHPTAL 165 Nov 17, 2021
View template engine of PHP extracted from Laravel

Blade 【简体中文】 This is a view templating engine which is extracted from Laravel. It's independent without relying on Laravel's Container or any others.

刘小乐 145 Aug 13, 2021
PHP 5.3 Mustache implementation

Phly\Mustache MOVED! This package has moved to phly/phly-mustache, and the package name has changed to phly/phly-mustache. I have updated packagist to

phly 124 Aug 17, 2021
A complete and fully-functional implementation of the Jade template language for PHP

Tale Jade for PHP Finally a fully-functional, complete and clean port of the Jade language to PHP — Abraham Lincoln The Tale Jade Template Engine brin

Talesoft 93 May 4, 2021
TextGenerator is a PHP package that aims to generate automated texts from data.

TextGenerator TextGenerator is a PHP package that aims to generate automated texts from data. Feel free to comment and contribute. Features Text gener

Vincent Brouté 85 Jul 19, 2021
A ready-to-use Model View Controller template in PHP

PHP-MVC-Template A ready-to-use Model View Controller template in PHP Use this repo as a template! (Or clone it) Start to configure your MVC file Afte

Loule | Louis 6 Nov 19, 2021
Derste birlikte hazırladığımız PHP Tema Motoru kaynak kodları

Prototürk Template Engine Prototürk'de sorulan bir soru üzerine videoda birlikte hazırladığımız php ile geliştirilmiş basit bir tema motoru. Geçerli d

Tayfun Erbilen 12 Nov 1, 2021
Provides a GitHub repository template for a PHP package, using GitHub actions.

php-package-template Installation ?? This is a great place for showing how to install the package, see below: Run $ composer require ergebnis/php-pack

null 260 Nov 24, 2021
The free-to-use template for your Imagehost-website made with PHP, HTML and CSS!

The free-to-use template for your Imagehost-website made with PHP, HTML and CSS! Some information before we start This repo is only code related, to a

Ilian 5 Nov 3, 2021