2. OPT parser configuration
The default OPT parser provides many options to increase or decrease the compatiblity with XML standard. In the most truncated version (so-called quirks mode) the parser looks for its own tags only, and the rest is treated as a static text, just like in PHP and Smarty. However, the default settings are chosen to provide the maximum possible compatibility with XML. OPT expects us to have a prolog in every template, properly closed tags and so on. Let's write a sample template:
<?xml version="1.0" ?> <opt:root> <ul> <li>Element</li> <li>Element</li> <li>Element</li> </ul> </opt:root>
After executing it and looking at the sources we could see that OPT displays everything in one line:
<ul> <li>Element</li> <li>Element</li> <li>Element</li> </ul>
It is not a bug. By default, OPT cuts the unnecessary white characters from the source code to reduce the output size and obfuscate the output code which is useful on production servers. But during the development we would like to keep the original form in order to make the analysis and debugging possible. In order to do this, we disable the configuration option
stripWhitespaces and recompile the template:
$tpl = new Opt_Class; // ... $tpl->stripWhitespaces = false;
To force the template recompilation, we remove the cached compiled version from the directory pointed by the
compileDir option. Let's take a look at the remaining options that affect XML syntax parsing:
- If it is set to false, the templates do not have to have a prolog (it is treated as a text to display, but still validated).
- If it is set to false, OPT allows to have more main tags in a single template.
- If it is enabled (true), OPT allows using a shortened attribute form without a value specified.
- If it is enabled (true), the XML comments are sent to the browser, too.
- The XML standard accepts the Unicode in the tag names, but due to the performance reasons it is disabled in OPT by default. This option lets us to enable it.
In this article we assume that OPT works with the default settings.