Open Power Template

Last updated
Open Power Template (OPT)
Developer(s) Invenzzia Group
Stable release
2.0.6 / September 3, 2010;14 years ago (2010-09-03)
Preview release
2.1-beta1 / September 3, 2010;14 years ago (2010-09-03)
Written in PHP
Type Template Engine
License BSD-like
Website www.invenzzia.org

Open Power Template is a web template engine written in PHP 5. A common strategy in designing web application is separation of the application logic (i.e. data processing) from the presentation (displaying the data). OPT is a tool for implementing such separation. The presentation layer is represented by templates, text files with HTML code and extra instructions controlling the data substitution.

Contents

OPT uses a dedicated XML template language to write templates. It is not a general-purpose, but a domain-specific language. It was primarily designed to support and simplify template-specific problems with a set of declarative instructions. Instead of implementing the rendering algorithms and statements, like in imperative programming, the template designer specifies the expected result and features. This aims to ease the costs and efforts associated with software development and further maintenance.

The library provides an object-oriented API based on the solutions from popular frameworks. As it is the first member of a bigger project, Open Power Libs, it is built upon a small OPL core library which provides the basic features.

History

The project started in November 2004, as a template engine for a discussion board project inspired by Smarty. While it later failed, the library became independent. In July 2006, the version 1.0.0 was released. It offered a template language with Smarty-like syntax and a small set of declarative instructions.

In January 2007, the developers release the version 1.1.0 which brings some notable improvements, such as pagination support and tree rendering.

In January 2008, the developers form an open-source programming team, Invenzzia to develop OPT and other PHP projects. At the same time, the development of Open Power Template 2.0 began.

The last version of the 1.1 branch was released in May 2008 and the group focused on the OPT 2.0 development. The new library went into the beta-stage in December and the first stable version was released in July 2009.

Features

The OPT 2.0 template language is an XML application that allows the manipulation of the XHTML document structure. The other features are:

  1. Template inheritance and other advanced template modularization mechanisms.
  2. Form rendering support (components)
  3. Abstract, declarative list generators (sections)
  4. Automated filtering against cross-site scripting attacks.
  5. Internationalization support.
  6. XML manipulation instructions.
  7. Imperative control structures: conditions and loops.
  8. Expression language optimized for XML and an abstraction layer making it independent from PHP data types and application-specific implementation details (data formats).

The built-in XML parser can be reconfigured to parse certain HTML documents or plain text content.

Sample application

Since the templates are separated from the application logic, you need at least two files. The first one contains the presentation code as an XML template:

<?xml version="1.0" ?><opt:rootescaping="yes"><opt:prologversion="1.0"/><opt:dtdtemplate="xhtml10transitional"/><html><head><title>{$pageTitle}</title><metahttp-equiv="content-type"content="text/html; charset=utf-8"/></head><body><p>{$introduction}</p><!-- display a list --><opt:showname="list"><ol><liopt:section="list">{$list.item}</li></ol></opt:show></body></html></opt:root>

The second one generates the data and configures the library:

require('./libs/Opl/Base.php');Opl_Loader::setDirectory('./libs/');Opl_Loader::register();$tpl=newOpt_Class;$tpl->sourceDir='./templates/';$tpl->compileDir='./templates_c/';$tpl->setup();$view=newOpt_View('template.tpl');// Assigning the script data to the template$view->pageTitle='Sample OPT page';$view->introduction='Sample text';$view->list=array(0=>array('item'=>'Item 1'),array('item'=>'Item 1'),array('item'=>'Item 1'));$view->setFormat('list','Array');$output=newOpt_Output_Http;$output->render($view);

Related Research Articles

XSLT is a language originally designed for transforming XML documents into other XML documents, or other formats such as HTML for web pages, plain text, or XSL Formatting Objects. These formats can be subsequently converted to formats such as PDF, PostScript, and PNG. Support for JSON and plain-text transformation was added in later updates to the XSLT 1.0 specification.

<span class="mw-page-title-main">PhpGedView</span>

PhpGedView is a free PHP-based web application for working with genealogy data on the Internet. The project was founded and is headed by John Finlay. It is licensed under the GPL-2.0-or-later license.

Smarty is a web template system written in PHP. Smarty is primarily promoted as a tool for separation of concerns. Smarty is intended to simplify compartmentalization, allowing the front-end of a web page to change separately from its back-end. Ideally, this lowers costs and minimizes the efforts associated with software maintenance.

Code injection is a class of computer security exploits in which vulnerable computer programs or system processes fails to correctly handle external data, such as user input, leading to the program misinterpreting the data as a command that should be executed. An attacker using this method "injects" code into the program while it is running. Successful exploitation of a code injection vulnerability can result in data breaches, access to restricted or critical computer systems and the spread of malware.

Apache Wicket, commonly referred to as Wicket, is a component-based web application framework for the Java programming language conceptually similar to JavaServer Faces and Tapestry. It was originally written by Jonathan Locke in April 2004. Version 1.0 was released in June 2005. It graduated into an Apache top-level project in June 2007.

Apache Velocity first released in April 2001, is a Java-based template engine that provides a template language to reference objects defined in Java code. It aims to ensure clean separation between the presentation tier and business tiers in a Web application.

Embedded Ruby is a templating system that embeds Ruby into a text document. It is often used to embed Ruby code in an HTML document, similar to ASP and JSP, and PHP and other server-side scripting languages. The templating system of eRuby combines Ruby code and plain text to provide flow control and variable substitution, thus making the combined code easier to maintain.

<span class="mw-page-title-main">Web template system</span> System in web publishing

A web template system in web publishing allows web designers and developers to work with web templates to automatically generate custom web pages, such as the results from a search. This reuses static web page elements while defining dynamic elements based on web request parameters. Web templates support static content, providing basic structure and appearance. Developers can implement templates from content management systems, web application frameworks, and HTML editors.

Sandcastle is a documentation generator from Microsoft. It automatically produces MSDN-style code documentation out of reflection information of .NET assemblies and XML documentation comments found in the source code of these assemblies. It can also be used to produce user documentation from Microsoft Assistance Markup Language (MAML) with the same look and feel as reference documentation.

Oracle BI Publisher is an enterprise reporting tool designed by Oracle. It was originally developed to solve the reporting problems faced by Oracle applications. The tool was first released with Oracle E-Business Suite 11.5.10 in 2003. Since then, it has been integrated into many Oracle products, including JD Edwards EnterpriseOne and PeopleSoft Enterprise 9. The tool was also released as a standalone version, with no dependency on other Oracle applications. It was rebranded as Oracle BI Publisher after becoming part of the Oracle Business Intelligence Suite Enterprise Edition.

JsonML, the JSON Markup Language is a lightweight markup language used to map between XML and JSON. It converts an XML document or fragment into a JSON data structure for ease of use within JavaScript environments such as a web browser, allowing manipulation of XML data without the overhead of an XML parser.

Haml is a templating system that is designed to avoid writing inline code in a web document and make the HTML cleaner. Similar to other template systems like eRuby, Haml also embeds some code that gets executed during runtime and generates HTML code in order to provide some dynamic content. In order to run Haml code, files need to have a .haml extension. These files are similar to .erb or .eRuby files, which also help embed Ruby code while developing a web application.

The syntax and semantics of PHP, a programming language, form a set of rules that define how a PHP program can be written and interpreted.

3DMLW is a discontinued open-source project, and a XML-based Markup Language for representing interactive 3D and 2D content on the World Wide Web.

XPath is an expression language designed to support the query or transformation of XML documents. It was defined by the World Wide Web Consortium (W3C) in 1999, and can be used to compute values from the content of an XML document. Support for XPath exists in applications that support XML, such as web browsers, and many programming languages.

Text Template Transformation Toolkit is a free and open-source template-based text generation framework. T4 source files are usually denoted by the file extension ".tt".

XQuery is a query and functional programming language that queries and transforms collections of structured and unstructured data, usually in the form of XML, text and with vendor-specific extensions for other data formats. The language is developed by the XML Query working group of the W3C. The work is closely coordinated with the development of XSLT by the XSL Working Group; the two groups share responsibility for XPath, which is a subset of XQuery.

Twig is a template engine for the PHP programming language. Its syntax originates from Jinja and Django templates. It's an open source product licensed under a BSD License and maintained by Fabien Potencier. The initial version was created by Armin Ronacher. Symfony PHP framework comes with a bundled support for Twig as its default template engine since version 2.

Mustache is a web template system. It is described as a logic-less system because it lacks any explicit control flow statements, like if and else conditionals or for loops; however, both looping and conditional evaluation can be achieved using section tags processing lists and anonymous functions (lambdas). It is named "Mustache" because of heavy use of braces, { }, that resemble a sideways moustache. Mustache is used mainly for mobile and web applications.