Location: PHPKode > projects > Open Power Template > docs/Opt/syntax.topics.quirks.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="pl">
<head>
	<meta http-equiv="content-type" content="text/html; charset=utf-8" />
	<meta name="robots" content="all" />

	<title>Quirks mode - Open Power Template</title>
	
	<link rel="stylesheet" type="text/css" href="design/generic.css" media="all"  />
	<link rel="stylesheet" type="text/css" href="design/print.css" media="print" />
	<!--[if lte IE 6]><link rel="stylesheet" href="design/ie.css" type="text/css" /><![endif]-->	
	<!--[if IE 7]><link rel="stylesheet" href="design/ie7.css" type="text/css" /><![endif]-->
</head>
<body>

<div id="wrap">
	<div id="header">
		<h1>Open Power Template 2.0</h1>
		<h2>Quirks mode</h2>
		<p class="generated">@ 02.09.2010</p>
		<p class="location"><a href="index.html"><strong>User manual</strong></a> &raquo; <a href="syntax.html">Template syntax</a> &raquo; <a href="syntax.topics.html">Topics</a> &raquo; <a href="syntax.topics.quirks.html">Quirks mode</a></p>
	</div>
	
	<div id="content"><dl class="location"><dt><a href="syntax.topics.html">3.9. Topics</a><br/>3.9.5. Quirks mode</dt><dd class="prev">3.9.4.2. Template inheritance<br/><a href="syntax.topics.modularization.inheritance.html">&laquo; Previous</a></dd><dd class="next">4. Programmer's Guide<br/><a href="guide.html">Next &raquo;</a></dd></dl>	<h1>3.9.5. Quirks mode</h1><p>Quirks mode is a special template parsing mode for the documents that do not have the XML document structure. It resembles the <em>XML compatibility mode</em> from Open Power Template 1.x. In this mode, everything that is not an OPT instruction or expression is treated as a plain text.</p>

<h2>Activation</h2>

<p>The quirks mode can be enabled globally by setting the <code>mode</code> configuration option:</p>

<pre class="php"><span style="color: #000088;">$tpl</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">mode</span> <span style="color: #339933;">=</span> Opt_Class<span style="color: #339933;">::</span><span style="color: #004000;">QUIRKS_MODE</span><span style="color: #339933;">;</span></pre>

<p>It can be also enabled for a single view:</p>

<pre class="php"><span style="color: #000088;">$view</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Opt_View<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'template.tpl'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$view</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setMode</span><span style="color: #009900;">&#40;</span>Opt_Class<span style="color: #339933;">::</span><span style="color: #004000;">QUIRKS_MODE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre>

<h2>Usage</h2>

<p>In quirks mode, only the OPT instructions and expressions are parsed and the compiler does not check anything else except entities. Below you can see a sample template:</p>

<pre class="xml"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;html<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Foo<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;p</span> <span style="color: #66cc66;">&#123;</span>$class<span style="color: #66cc66;">&#125;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>This is a text
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ol<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;opt:section</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;foo&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;li<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>{$foo.item}
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/opt:section<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ol<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/HTML<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre>

<p>The ordinary HTML tags are not validated, so you do not have to close them properly. On the other hand, the OPT tags still must be enclosed in the valid order. Moreover, the expressions in curly brackets may be used as attribute sources for the tags. Moreover, the output systems allow to concatenate the output document from the smaller pieces.</p>

<h2>Limitations</h2>

<p>The quirks mode brings some limitations:</p>

<ol>
<li>No XML/HTML error control.</li>
<li>OPT attributes cannot be used with HTML tags.</li>
<li>You cannot use any features that are supposed to co-operate with the ordinary (non-OPT) tags in the document.</li>
</ol>

<h2>When to use the quirks mode?</h2>

<p>The quirks mode has been designed for processing the non-XML documents without the need to use a separate template engine for them. This includes for example SQL, CSV or plain text files. It is not recommended to use it with HTML and (especially) XHTML, as it may lead to serious problems in the future.</p>
<dl class="location location-bottom"><dt>3.9.5. Quirks mode<br/><a href="syntax.topics.html">3.9. Topics</a></dt><dd class="prev"><a href="syntax.topics.modularization.inheritance.html">&laquo; Previous</a><br/>3.9.4.2. Template inheritance</dd><dd class="next"><a href="guide.html">Next &raquo;</a><br/>4. Programmer's Guide</dd></dl>		</div>
	
	<div id="footer">
		<p>Copyright &copy; <a href="http://www.invenzzia.org/">Invenzzia Group 2008-2009</a></p>
		<p>Available under the terms of license: <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation License 1.2</a></p>
		<p>Generated by <strong>TypeFriendly 0.1.4</strong> by <a href="http://www.invenzzia.org/">Invenzzia</a></p>
	</div>
</div>

</body>
</html>
Return current item: Open Power Template