Open Power Template

Open Power Template
Open Power Template (OPT)
Developer(s) Invenzzia Group
Stable release 2.0.6 / September 3, 2010; 13 months ago (2010-09-03)
Preview release 2.1-beta1 / September 3, 2010; 13 months 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.

OPT uses a dedicated XML template language for writing 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 the 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.

Contents

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 and allows to manipulate 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:root escaping="yes">
  <opt:prolog version="1.0" />
  <opt:dtd template="xhtml10transitional" />
  <html>
    <head>
      <title>{$pageTitle}</title>
      <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    </head>
    <body>
      <p>{$introduction}</p>
 
      <!-- display a list -->
      <opt:show name="list">
      <ol>
        <li opt: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 = new Opt_Class;
$tpl->sourceDir = './templates/';
$tpl->compileDir = './templates_c/';
$tpl->setup();
 
$view = new Opt_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 = new Opt_Output_Http;
$output->render($view);

Links and references


Wikimedia Foundation. 2010.

Игры ⚽ Нужна курсовая?

Look at other dictionaries:

  • Open Your Heart (Madonna song) — Open Your Heart Single by Madonna from the album True Blue B side …   Wikipedia

  • Open Arms (Journey song) — Open Arms Single by Journey from the album Escape and Heavy Metal Soundtrack …   Wikipedia

  • Open Mind Common Sense — (OMCS) is an artificial intelligence project based at the Massachusetts Institute of Technology (MIT) Media Lab whose goal is to build and utilize a large commonsense knowledge base from the contributions of many thousands of people across the… …   Wikipedia

  • Low-power broadcasting — Contents 1 United States 1.1 FM radio 1.1.1 LPFM classes 1.1.2 …   Wikipedia

  • Kansas City Power & Light District — Infobox Venue name = Power Light District image caption = nickname = location = 1100 Walnut Street Suite 3000 Kansas City, Missouri 64106 coordinates = Coord|39|05|52|N|94|34|56|W|region:US type:landmark type = Mixed use retail, entertainment,… …   Wikipedia

  • Stella Power Station — Infobox UK power station static static image caption=Stella North and South Power Stations. Viewed from Newburn Bridge on 31 October 1987. Stella North is on the left and Stella South is on the right. os grid reference=NZ175644 latitude=54.974278 …   Wikipedia

  • The Decline of British Sea Power — Studio album by British Sea Power Released 2 Jun …   Wikipedia

  • Comparison of open source configuration management software — This is a comparison of free (libre) and open source configuration management software. Contents 1 Basic properties 2 Platform support 3 Short descriptions 4 Refere …   Wikipedia

  • Cockenzie power station — Viewed from the south in March 2003 …   Wikipedia

  • Eraring Power Station, New South Wales — Introduction Eraring Power Station is one of two coal fired electricity power stations on the shores of Lake Macquarie. Eraring is located on the western shore of the lake, near the township of Dora Creek. It has four steam driven turbine… …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”