OPT 1.x vs OPT 2.x - explaination
From Invenzzia wiki
The history of Open Power Template began in 2004. Due to its long presency, there are many materials on the Internet that refer to the older versions of this library. This article provides a small explaination to this situation for the new users that may be confused.
Contents |
General overview
There are two major versions of Open Power Template, that are actually completely different template engines.
- Open Power Template 1.x - one of the first template engines for PHP5 developed since 2004 to 2008.
- Open Power Template 2.x - the successor of the 1.x version, redesigned and reimplemented from scratch. It is being developed since early 2008.
Currently, there are plenty of articles that refer to the first version. However, its development is cancelled now and we recommend to take a closer look at OPT 2.x. Below you can find some information on both of the two branches.
Open Power Template 1.x
OPT appeared as a template engine developed for the Polish discussion board project, Open Power Board. Initially, it was a project with a Smarty-like syntax, but with some enhancements, like sections that were quite similar to those used today. OpenPB was actually cancelled quite fast and OPT was the only subproject that survived the crash and acquired the network infrastructure. For a long time, it existed only as development versions with poor support, unstable syntax and API. However, in 2006 I managed to release a first stable version, 1.0.0. A couple of months later, the new brach, 1.1.0 with several improvements was introduced. The library became quite popular in Poland due to the native support and advanced features, but in English-language countries it was rather unknown.
OPT 1.x contained several features that were extended in OPT 2.x. One of them are smart loops called sections:
<html>
<head>
<title>Open Power Template: musical albums</title>
</head>
<body>
<h3>My album list</h3>
<ul>
{section=album}
<li>{$album.title} - {$album.band} ({$album.year})</li>
{/section}
</ul>
</body>
</html>
There were also components used for the same purpose, but their design was completely different:
<html>
<head>
<title>Open Power Template: components</title>
</head>
<body>
<form method="get" action="components.php">
Select your category:
{selectComponent name="selected" message="$message" datasource="$list"}
{param name="selected" value="$selected"/}
{onmessage message="msg" position="down"}
<font color="red">{@msg}</font>
{/onmessage}
{/selectComponent}
<input type="submit" value="OK"/>
</form>
</body>
</html>
OPT 1.x did not understand the XML and HTML syntax which was treated as a static text. However, there was a feature called XML compatibility mode, where the OPT tags looked more like XML. Unfortunately, it was only an eye-candy modification. Among the other features, there were:
- I18n support.
- Smart expression parser that was able to detect the syntax errors.
- Caching subsystem.
- Plugin architecture.
- Snippets.
- Tree rendering and pagination support.
- A PHP code preprocessor that allowed to remove the unused features directly from OPT source code, reducing the size of the library.
Together with OPT 1.x, there was developed an add-on called Open Power Forms. It was a form processing and data validation library integrated with OPT. It allowed to build dynamic HTML forms in OPT templates without the need of developing your own components, validation utilities and error handling. A stable version was never released.
Open Power Template 2.0
In 2007, it became clear that the design and concepts of the projects must be changed. There was a criticism that OPT was in fact a yet another Smarty clone and many people wanted to have a tool that was really useful while working with XHTML and HTML templates. At the end of the year, I made some experiments with processing the XML documents and the XML compiler prototype was ready in November. In January 2008, Invenzzia was founded and since then the 2.0 branch became reality. One of the goals was bilingual Polish and English support which was a mistake, so we decided to reduce the Polish support and provide international, English-language materials only. In January 2009, Invenzzia released the first beta version of OPT 2.x and with the help of the community, we are on the way to release the first stable version.
Open Power Template 2.0 is a completely different library with significant API and syntax changes. The template language is based on XML and the compiler checks the validity of both the OPT-related tags and the processed XML/HTML. Many of the features were improved to suit different needs and purposes. Moreover, many of the less used behaviour became standarized. OPT 2.0 pays a big attention to the declarative programming that releases the template designer from dealing with the implementation issues. Instead, he can concentrate on what we wants to see rather than how it must work. The new API uses many advanced PHP5 features, such as autoloaders, real data hermetization, better use of objects and stream support. Its design is similar to the solutions used in popular frameworks such as Symfony or Zend Framework. Moreover, OPT 2.0 is not a standalone library anymore. Instead, it requires a small library called Open Power Libs Core (included in every release of OPT) that provides the common features for different OPL libraries, such as autoloader, plugin and configuration architecture or error handling. This wiki provides the information on OPT 2.0 branch only.
In the near future, OPT will not be the only OPL library. Currently, we are preparing to release a set of utility classes as well as reactivating the Open Power Forms project integrated with OPT 2.0 and based on the best form processing solutions from popular frameworks.
Conclusion
We hope that this article helped you to understand some issues related to the Open Power Template project history. If you wish to start a new project, we recommend you to choose OPT 2.0 branch. It is quite stable now and the number of things that do not work or work incorrectly decreases every week. Moreover, Invenzzia provides the full English support for this release, as well as releases new tutorials, code samples and extensions.

