Invenzzia »

Open Power Libraries

PHP5 libraries

Open Power Libraries » FAQ: Open Power Template

FAQ: Open Power Template


General Questions

Why should I use a template engine?
In our opinion, every web application more advanced than simple “Hello world” should use a template engine. I does not have to have the same form, as OPT, however it should be.

The template engine improves the development process and makes the project easier to modify. I.e. imagine you have to change the layout of whole site. If the HTML and PHP code is placed in the same file, it’s rather hard.

May I use OPT in a commercial project?
Yes, the LGPL licence allows you to do that. However, you must not get money for using it (for example: «If you pay us extra $100, we will use OPT» – such practices are forbidden and illegal).

Template Syntax Questions

Foobarowe pytanie
Lorem ipsum
The default OPT syntax does not work with W3C XHTML Validator.
OPT may work in xml-syntax mode, where the default delimiters are replaced by XML-compatible ones. It may be enabled by setting the xmlsyntaxMode directive to 1. If you plan to use the if command, enable also this one: strictSyntax.

<ul>
<opt:section name="name">
<opt:if test="$opt.section.name.first">
<li><b><a href="{$name.href}" opt:put="$name.additional_params">{$name.value}</a></b></li>
<opt:else/>
<li><a href="{$name.href}" opt:put="$name.additional_params">{$name.value}</a></li>
</opt:if>
</opt:section>
</ul>

Don’t forget it is only an emulation. OPT does not have any XML parser that could check the syntax, so (for example) it accepts opt:put="code" outside the HTML tags.

Can I get the data directly from the database?
In OPT, you can build the configuration as an array and pass it manually to OPT. This sample shows that:

<?php 
// manual configuration loading 
$config = parse_ini_file('opt_config.ini'); 
// changing the directories 
$config['root'] = 'templates/'.$style.'/'; 
$config['compile'] = 'templates_c/'.$style.'/'; 
$tpl->loadConfig($config);
?>

You may also set each directive in the same way, like in Smarty(tm) package.

Foobarowe pytanie
Lorem ipsum