2017 © Pedro Peláez
 

library templating-engine

Like Smarty, but faster

image

skrz/templating-engine

Like Smarty, but faster

  • Wednesday, July 22, 2015
  • by jakubkulhan
  • Repository
  • 4 Watchers
  • 1 Stars
  • 14,391 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 5 % Grown

The README.md

Skrz.cz templating engine

Like Smarty, but faster, (*1)

Why?

At Skrz.cz, the largest Czech best-prices search engine, we heavily use Smarty. However, Smarty's official implementation ceased to meet our needs, mainly regarding performance., (*2)

Skrz\Templating\Engine is Smarty syntax-compatible. Not every Smarty construct has been implemented. You can think of what has been implemented as the good parts., (*3)

Key design decisions are:, (*4)

  • Compile time and run time are strictly separated. When you do ->display(...), or ->fetch(...) in Smarty, many things can happen. Smarty checks if the template has been compiled, if compiled code is still valid, if cached content hasn't been hit, etc. Skrz\Templating\Engine does none of that., (*5)

  • Compilation is managed by external tool. At Skrz we use Grunt to compile CSS, Javascript, and also templates in development., (*6)

  • Compilation output is an autoload-able class, rendering should be encapsulated in a method. Smarty compiles templates into a bunch of functions that reside inside if statements, so they cannot be declared twice. With JIT-ing PHP implementations coming up (HHVM, PHP-NG, HippyVM), this is quite sub-optimal, because certain optimizations cannot be applied (e.g. HHVM can optimize file inclusion that only contains classes at the top level, into just populating class tables)., (*7)

Usage

Skrz\Templating\Engine provides only parser and compiler. Please refer to tests on how they are used., (*8)

Basically, you just create ParserContext, parse template file, create CompilerContext, and compile into output file., (*9)

Let's say, you have template MyTemplate.tpl in current directory and want to compile it into MyTemplate.php:, (*10)

$outputFileName = __DIR__ . "/MyTemplate.php";

$parserContext = new ParserContext();
$parserContext
    ->addPath(__DIR__);
    ->setFile("MyTemplate.tpl");

$compilerContext = new CompilerContext();
$compilerContext
    ->setParserContext($parserContext)
    ->setClassName("MyTemplate")
    ->setTemplate($parserContext->parse())
    ->setOutputFileName($outputFileName)
    ->dump();

License

The MIT license. See LICENSE file., (*11)

The Versions

22/07 2015

dev-master

9999999-dev

Like Smarty, but faster

  Sources   Download

MIT

The Development Requires

templating smarty templates template engine fast templating engine

18/02 2015

v1.1.2

1.1.2.0

Like Smarty, but faster

  Sources   Download

MIT

The Development Requires

templating smarty templates template engine fast templating engine

18/02 2015

v1.1.1

1.1.1.0

Like Smarty, but faster

  Sources   Download

MIT

The Development Requires

templating smarty templates template engine fast templating engine

18/02 2015

v1.1.0

1.1.0.0

Like Smarty, but faster

  Sources   Download

MIT

The Development Requires

templating smarty templates template engine fast templating engine

13/08 2014

v0.1.0

0.1.0.0

Like Smarty, but faster

  Sources   Download

MIT

The Development Requires

templating smarty templates template engine fast templating engine

13/08 2014

v1.0.0

1.0.0.0

Like Smarty, but faster

  Sources   Download

MIT

The Development Requires

templating smarty templates template engine fast templating engine