<?xml version="1.0" encoding="utf-8"?><?xml-stylesheet title="XSL formatting" type="text/xsl" href="http://blog.invenzzia.org/en/feed/rss2/xslt" ?><rss version="2.0"
  xmlns:dc="http://purl.org/dc/elements/1.1/"
  xmlns:wfw="http://wellformedweb.org/CommentAPI/"
  xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
  <title>Invenzzia... in English - OPT2</title>
  <link>http://blog.invenzzia.org/en/</link>
  <description></description>
  <language>en</language>
  <pubDate>Fri, 25 Jul 2008 17:12:15 +0100</pubDate>
  <copyright>Copyright &amp;copy; Invenzzia</copyright>
  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
  <generator>Dotclear</generator>
  
    
  <item>
    <title>OPT 2.0.0-dev4</title>
    <link>http://blog.invenzzia.org/en/post/OPT-200-dev4</link>
    <guid isPermaLink="false">urn:md5:53f051a3804ea8fd52e637f321aaa683</guid>
    <pubDate>Sun, 02 Mar 2008 11:28:00 +0100</pubDate>
    <dc:creator>Zyx</dc:creator>
        <category>Open Power Template</category>
        <category>OPT2</category>    
    <description>&lt;p&gt;There is a new Open Power Template development version available to download. The project begins to gel, as the main parser class is almost completed. Inspite of the output cache system mentioned earlier, I've implemented new instructions and completed the snippets. It means that all the template inheritance should work now. I hope the library will be usable by the end of this month. The real projects are really necessary to detect possible bugs and various shortcomings.&lt;/p&gt;    &lt;p&gt;In snippets, we have a new possibility to insert the parent content using the &lt;code&gt;opt:parent&lt;/code&gt; tag:&lt;/p&gt;

&lt;pre name=&quot;code&quot; class=&quot;xml&quot;&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot; standalone=&amp;quot;yes&amp;quot; ?&amp;gt;
&amp;lt;opt:extend file=&amp;quot;test_inherited_a.tpl&amp;quot;&amp;gt;
	&amp;lt;opt:snippet name=&amp;quot;header&amp;quot;&amp;gt;
		&amp;lt;h1&amp;gt;Webmaster Of Puppets&amp;lt;/h1&amp;gt;
		&amp;lt;p&amp;gt;Here is the parent content:&amp;lt;/p&amp;gt;
		&amp;lt;opt:parent/&amp;gt;
		&amp;lt;p&amp;gt;End of the parent content&amp;lt;/p&amp;gt;
	&amp;lt;/opt:snippet&amp;gt;
&amp;lt;/opt:extend&amp;gt;
&lt;/pre&gt;


&lt;p&gt;In this case, if the &lt;em&gt;test_inherited_a.tpl&lt;/em&gt; contains another snippet with the same name, its content will be put in the place of &lt;code&gt;opt:parent&lt;/code&gt;. Such nesting works much deeper. For example, let's say that snippet also uses this tag. OPT will try to locate another parent and so on. It is even possible to put the default content of the &lt;code&gt;opt:insert&lt;/code&gt; tag, which is used to place the snippets. The code contains also a simple code to detect the infinite recursion. If the parser finds it, it returns an exception and the programmer sees a nice, red error message :).&lt;/p&gt;


&lt;p&gt;During the using of the new OPT, the new debug console should be also useful. It has been extended, compared to the similar option in OPT 1.1.x. The most significant change is splitting the list of templates to the smaller ones which show different information:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Executed templates&lt;/li&gt;
&lt;li&gt;Currently compiled templates&lt;/li&gt;
&lt;li&gt;Templates read from cache.&lt;/li&gt;
&lt;li&gt;Inherited templates - it shows all the inheritance chains, as well, as the information whether they have been recompiled or not.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Moreover, the console displays all the warnings. They are no longer put onto the screen, but available only with the debug console or error messages, if we set the proper debug level.&lt;/p&gt;


&lt;p&gt;The performance issue also looks very good. The total size of &lt;em&gt;opt.class.php&lt;/em&gt; file is about 25 KB, compared to 32 KB in the OPT 1.1.x. Currently, its size influences the performance much, as PHP must load the parser and compile it to the internal bytecode. Of course, if we parse a lot of templates, it won't be so visible, however I'm quite pleased of the effect.&lt;/p&gt;


&lt;p&gt;The package can be downloaded from &lt;a href=&quot;http://www.invenzzia.org/download/opt-2.0.0-dev4.tar.gz&quot; hreflang=&quot;en&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;</description>
    
    
    
          <comments>http://blog.invenzzia.org/en/post/OPT-200-dev4#comment-form</comments>
      <wfw:comment>http://blog.invenzzia.org/en/post/OPT-200-dev4#comment-form</wfw:comment>
      <wfw:commentRss>http://blog.invenzzia.org/en/feed/rss2/comments/18</wfw:commentRss>
      </item>
    
  <item>
    <title>The main class almost finished</title>
    <link>http://blog.invenzzia.org/en/post/The-main-class-almost-finished</link>
    <guid isPermaLink="false">urn:md5:a4135d6c62812ecd599e53cd4933d0d1</guid>
    <pubDate>Fri, 22 Feb 2008 08:59:00 +0100</pubDate>
    <dc:creator>Zyx</dc:creator>
        <category>Open Power Template</category>
        <category>OPT2</category>    
    <description>&lt;p&gt;The result of the latest works on the OPT source code is complete &lt;em&gt;opt.class.php&lt;/em&gt; file which contains (as some of the readers may know) the main parser class. I must admit that this file was more demanding that the compiler. In the second case we can afford with quite a lot. Just an idea for the algorithm and prediction if and how it will influence the rest of the code. In the case of the main class, we must pay attention to the performance. It must contain everything that is run permanently and it must be fast and small. But the number of features is getting bigger and bigger.&lt;/p&gt;    &lt;p&gt;The new development version will not be compatible with the previous ones when it comes to the programming interface. To implement the output cache system, I had to rebuild almost all of the output system. In the 1.x.x series, the concept of the output system did not exist. Either the result will be seen on the screen or put into a variable, it depended on the right method choice. There were some tricky connections which redirected everything to the right place, however it was not well designed and a bit messy. Well, such things simply must happen, if we start with keeping the similarities to Smarty, and I have to remind that in the very early times, it was one of the OPT goals. In OPTv2, there is a well-declared &lt;em&gt;ioptOutput&lt;/em&gt; interface allowing the programmer to code the output processing on his own. It is also used in the implementation of output cache system. How - it is explained below.&lt;/p&gt;


&lt;p&gt;So far, there have been two output systems: &lt;em&gt;optNetOutput&lt;/em&gt; sending everything on the screen and checking, how many templates we are going to send in the XML mode. The second one was &lt;em&gt;optReturnOutput&lt;/em&gt;, which returned the result. I added a possibility to decorate them with something else and I created &lt;em&gt;optCachedOutput&lt;/em&gt;. Its only goal is to process the cache. The features are the same as in the previous versions, but the usage is a bit different and unfortunately, the initialization is more complicated:&lt;/p&gt;

&lt;pre name=&quot;code&quot; class=&quot;php&quot;&gt;$cache = new optCachedOutput('./cache/'); // this is the cache, here we configure it
$tpl -&amp;gt; register(OPT_OUTPUT, 'my_cache', $cache);
$tpl -&amp;gt; decorate(OPT_OUT_SCREEN, 'my_cache');
$tpl -&amp;gt; decorate(OPT_OUT_RETURN, 'my_cache');

if(!$cache -&amp;gt; isCached('template.tpl', 'some_id'))
{
  // data generation
}

$cache -&amp;gt; setCache(5, 'some_id'); // turn the cache on for 5 seconds
$tpl -&amp;gt; parse('template.tpl', 'my_cache');
&lt;/pre&gt;


&lt;p&gt;I'll try to shorten it and make simpler the first lines of the code, because I don't like them, too. Moreover, I must check if I've made the decoration in the right way (according to the logic).&lt;/p&gt;


&lt;p&gt;The support for plugins is not fully completed yet. The only ready part is placed in &lt;em&gt;opt.class.php&lt;/em&gt; file. The rest is moved somewhere else, which should improve the performance. Like in OPT 1.1.3, there will be a possibility to set many plugin directories, but the parser will not require them to be writeable. There were thrown some files describing the content and allowing to include everything without scanning all the directory. As we know, the more includes, the less performance and some people can produce more plugins than all the files in my framework :). The new OPT will try to link all these files into one, mega-file containing everything we need. By the way, I'll have also a new algorithm for the OPT Toolset sequel, which will be used now for all the libraries, not only OPT.&lt;/p&gt;


&lt;p&gt;The last issue concerns the available function set for the templates. Stormfly has recently written on his blog that OPT 1.1.x it was quite senseless and in fact, he was right. I took a look, what Smarty offers and it turned out that it has some nice and useful functions. The first list looks like that:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;em&gt;spacify&lt;/em&gt; - puts a string between every two neighbour characters in the text.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;indent&lt;/em&gt; - makes an indentation in the text.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;truncate&lt;/em&gt; - reduces the text to the specified length (allowing not to splitting the words)&lt;/li&gt;
&lt;li&gt;&lt;em&gt;strip&lt;/em&gt; - reduces all the white character groups to a single character&lt;/li&gt;
&lt;li&gt;&lt;em&gt;capitalize&lt;/em&gt; - equivalent to ucfirst()&lt;/li&gt;
&lt;li&gt;&lt;em&gt;upper&lt;/em&gt; - equivalent to strtoupper()&lt;/li&gt;
&lt;li&gt;&lt;em&gt;lower&lt;/em&gt; - equivalent to strtolower()&lt;/li&gt;
&lt;li&gt;&lt;em&gt;countWords&lt;/em&gt; - equivalent to str_word_count()&lt;/li&gt;
&lt;li&gt;&lt;em&gt;countChars&lt;/em&gt; - equivalent to strlen()&lt;/li&gt;
&lt;li&gt;&lt;em&gt;money&lt;/em&gt; - equivalent to money_format(), but the settings can be written in the OPT configuration.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;number&lt;/em&gt; - equivalent to number_format(), but the settings can be written in the OPT configuration.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;wordWrap&lt;/em&gt; - equivalent to word_wrap()&lt;/li&gt;
&lt;li&gt;&lt;em&gt;replace&lt;/em&gt; - equivalent to str_replace()&lt;/li&gt;
&lt;li&gt;&lt;em&gt;regexReplace&lt;/em&gt; - equivalent to preg_replace(), but the parameter order is changed.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;date&lt;/em&gt; - equivalent to date() :)&lt;/li&gt;
&lt;li&gt;&lt;em&gt;firstof&lt;/em&gt; - returns the first non-empty element from the specified ones.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;nl2br&lt;/em&gt; - equivalent to nl2br() :)&lt;/li&gt;
&lt;li&gt;&lt;em&gt;array&lt;/em&gt; - creating arrays on the template side&lt;/li&gt;
&lt;li&gt;&lt;em&gt;build&lt;/em&gt; - it was called &quot;apply()&quot; in the previous versions, but I still don't know, whether I keep this name or not.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The set contains no escaping functions, because the compiler is able to put them on his own in most of the places. There will be a possibility to escape something manually, but it won't be done through functions. Anyway, the point is the compiler must know, what is escaped. Otherwise it may add additional function call and this would produce a complete mess on the screen.&lt;/p&gt;


&lt;p&gt;To sum up, I've written so much functionality that I haven't tested all of them yet. I don't know if something works, however I don't expect any revelations. Many of the algorithms are reimplementations of the same code from OPT 1.1.x.  The next dev version will be available in the nearest days.&lt;/p&gt;


&lt;p&gt;Some statistics for the end:&lt;/p&gt;


&lt;blockquote&gt;&lt;p&gt;- &lt;em&gt;opt.class.php&lt;/em&gt; - 24 KB and still growing. In OPT 1.1.x, this file was 8 KB bigger, but offered less functionality.&lt;br /&gt;
- &lt;em&gt;opt.compiler.php&lt;/em&gt; - 65 KB and still growing.&lt;br /&gt;
- &lt;em&gt;opt.instructions.php&lt;/em&gt; - 25 KB and still growing.&lt;/p&gt;&lt;/blockquote&gt;</description>
    
    
    
          <comments>http://blog.invenzzia.org/en/post/The-main-class-almost-finished#comment-form</comments>
      <wfw:comment>http://blog.invenzzia.org/en/post/The-main-class-almost-finished#comment-form</wfw:comment>
      <wfw:commentRss>http://blog.invenzzia.org/en/feed/rss2/comments/14</wfw:commentRss>
      </item>
    
  <item>
    <title>OPT 2.0.0-dev3</title>
    <link>http://blog.invenzzia.org/en/post/OPT-200-dev3</link>
    <guid isPermaLink="false">urn:md5:9843f60585ccf157ee19a973402b4cd2</guid>
    <pubDate>Fri, 15 Feb 2008 13:26:00 +0100</pubDate>
    <dc:creator>Zyx</dc:creator>
        <category>Open Power Template</category>
        <category>OPT2</category>    
    <description>&lt;p&gt;According to the my announcement from the last week, the development versions are going to appear much faster than before. This is the first of such events. The third dev of OPT 2.0.0 is ready to download. This time, I've paid much attention to the attribute processing. They can do a lot of interesting things with the tags they've been added to. The earl implementation has been ready so far - there were even examples showing the &quot;opt:section&quot; working. But to satisfy both me and probably other programmers, I had to extend it.&lt;/p&gt;    &lt;p&gt;Here are some examples showing, what can be done now. Let's start from something simple. In OPT, we use curly brackets to put expressions into a text, like:&lt;/p&gt;

&lt;pre name=&quot;code&quot; class=&quot;html&quot;&gt;text text text {$block} text text text
&lt;/pre&gt;


&lt;p&gt;There is also &lt;code&gt;opt:put&lt;/code&gt; instruction, which does the same for the first time we see it:&lt;/p&gt;

&lt;pre name=&quot;code&quot; class=&quot;html&quot;&gt;text text text &amp;lt;opt:put value=&amp;quot;$block&amp;quot;/&amp;gt; text text text
&lt;/pre&gt;


&lt;p&gt;However, it is an instruction, not curly brackets. It means we can make some nice things with it using attributes. Let's say we want to display something like &quot;Value 1 / Value 2 / Value 3&quot;. We will use &lt;code&gt;opt:put&lt;/code&gt;, a section and a separator:&lt;/p&gt;

&lt;pre name=&quot;code&quot; class=&quot;html&quot;&gt;&amp;lt;p&amp;gt;&amp;lt;opt:put value=&amp;quot;$section.value&amp;quot; opt:section=&amp;quot;section&amp;quot; str:separator=&amp;quot; / &amp;quot;/&amp;gt;&amp;lt;/p&amp;gt;
&lt;/pre&gt;


&lt;p&gt;As we see, such section affects also the tag which it was linked to and we can put the values of section elements in the attributes. The separator accepts expressions by default, but if we don't like writing &lt;em&gt;separator=&quot;'something'&quot;&lt;/em&gt; (double, and then a single quote), we can just switch the namespace to &quot;str&quot;.&lt;/p&gt;


&lt;p&gt;The implementation of reversed quotes is also ready. Compared to the previous versions, they change their function. Now it is the programmer who can give them a meaning and program them to do what he wants. It can be done by writing a simple function and giving its name to the parser. A sample use is an elegant implementation of language system a'la gettext:&lt;/p&gt;

&lt;pre name=&quot;code&quot; class=&quot;html&quot;&gt;&amp;lt;p&amp;gt;{`Some useful information...`}&amp;lt;/p&amp;gt;
&amp;lt;p&amp;gt;{`Author:`} {$author}&amp;lt;/p&amp;gt;
&lt;/pre&gt;


&lt;p&gt;This is the last of the changes. As we have an XML compiler, we need some special instructions that allow to manage the tree directly, for example by adding an attribute with a variable name. OPT is going to provide two instructions for this task: &lt;code&gt;opt:tag&lt;/code&gt; and &lt;code&gt;opt:attribute&lt;/code&gt;. The second one has been already added to the newest dev. We can use it to read the attribute name from the block:&lt;/p&gt;
&lt;pre name=&quot;code&quot; class=&quot;html&quot;&gt;&amp;lt;div&amp;gt;
  &amp;lt;opt:attribute name=&amp;quot;$some_name&amp;quot; value=&amp;quot;$some_value&amp;quot;/&amp;gt;
  body...
&amp;lt;/div&amp;gt;
&lt;/pre&gt;


&lt;p&gt;This is not the end - connected with sections, we get a powerful tool to add a lot of new attributes:&lt;/p&gt;

&lt;pre name=&quot;code&quot; class=&quot;html&quot;&gt;&amp;lt;div&amp;gt;
  &amp;lt;opt:attribute name=&amp;quot;$attr.name&amp;quot; value=&amp;quot;$attr.value&amp;quot; opt:section=&amp;quot;attr&amp;quot;/&amp;gt;
  body...
&amp;lt;/div&amp;gt;
&lt;/pre&gt;


&lt;p&gt;If we send the following table to this template: &lt;code&gt;array(0 =&amp;gt; array('name' =&amp;gt; 'class', 'value' =&amp;gt; 'dude'), array('name' =&amp;gt; 'id', 'value' =&amp;gt; 'lol'))&lt;/code&gt;, the result will be:&lt;/p&gt;

&lt;pre name=&quot;code&quot; class=&quot;html&quot;&gt;&amp;lt;div class=&amp;quot;dude&amp;quot; id=&amp;quot;lol&amp;quot;&amp;gt;
  body...
&amp;lt;/div&amp;gt;
&lt;/pre&gt;


&lt;p&gt;Unfortunately, the English manual is not started yet, but it will be ready before the first stable release.&lt;/p&gt;


&lt;p&gt;Download: &lt;a href=&quot;http://blog.invenzzia.org/en/post/&quot; hreflang=&quot;en&quot;&gt;http://www.invenzzia.org/download/opt-2.0.0-dev3.tar.gz&lt;/a&gt;&lt;/p&gt;</description>
    
    
    
          <comments>http://blog.invenzzia.org/en/post/OPT-200-dev3#comment-form</comments>
      <wfw:comment>http://blog.invenzzia.org/en/post/OPT-200-dev3#comment-form</wfw:comment>
      <wfw:commentRss>http://blog.invenzzia.org/en/feed/rss2/comments/11</wfw:commentRss>
      </item>
    
  <item>
    <title>New dev</title>
    <link>http://blog.invenzzia.org/en/post/New-dev</link>
    <guid isPermaLink="false">urn:md5:a5d8cceafecfd239ba372c9cd993b8be</guid>
    <pubDate>Sat, 09 Feb 2008 11:02:00 +0100</pubDate>
    <dc:creator>Zyx</dc:creator>
        <category>Open Power Template</category>
        <category>OPT2</category>    
    <description>&lt;p&gt;The website now has the &quot;Download&quot; page. In it, you can find a new development version of Open Power Template. It also contains a simple script &quot;docgen&quot; which we use for automated generation of the DocBook manuals. The new development versions should appear now much more often than before. In case of many new features, they might appear even every 2-3 days. The reason why this was impossible in the past was the time. The process was not automated and it takes a while to prepare such archive (for example - it takes a couple of hours to publish new OPT 1.x version on the Internet).&lt;/p&gt;    &lt;p&gt;The pack contains everything I've implemented for last month:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Nearly completed sections.&lt;/li&gt;
&lt;li&gt;Separators.&lt;/li&gt;
&lt;li&gt;&quot;For&quot; and &quot;Foreach&quot; loops.&lt;/li&gt;
&lt;li&gt;Mostly completed template inheritance.&lt;/li&gt;
&lt;li&gt;HTTP header management.&lt;/li&gt;
&lt;li&gt;Partially completed prolog parser.&lt;/li&gt;
&lt;li&gt;Some fixes in the compiler.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The &quot;/dev&quot; directory contains some scripts that are used to test the new features. There are also unit tests: a complete set to test the expression parser and a part of the API test. There will be also a one to process the instructions, however the whitespace characters cause many problems, when it comes to prepare the files. If we try to compare the generated content with the expected result, we have to watch out on every space or line break. Otherwise the test fails, so you must be very patient to write a simple, stupid test. But I think this issue will be solved. To work, the tests require &quot;phpUnit 3&quot; package available in PEAR.&lt;/p&gt;</description>
    
    
    
          <comments>http://blog.invenzzia.org/en/post/New-dev#comment-form</comments>
      <wfw:comment>http://blog.invenzzia.org/en/post/New-dev#comment-form</wfw:comment>
      <wfw:commentRss>http://blog.invenzzia.org/en/feed/rss2/comments/10</wfw:commentRss>
      </item>
    
  <item>
    <title>Template inheritance</title>
    <link>http://blog.invenzzia.org/en/post/Template-inheritance</link>
    <guid isPermaLink="false">urn:md5:18f9793a8c4c1405788e24861aa04ef1</guid>
    <pubDate>Sat, 02 Feb 2008 17:03:00 +0100</pubDate>
    <dc:creator>Zyx</dc:creator>
        <category>Open Power Template</category>
        <category>OPT2</category>    
    <description>&lt;p&gt;Unsually, the final HTML code of the website is composed of several smaller templates containing smaller pieces of it. There are many techniques of combining them. In PHP template engines, the most popular are two forms: manual execution of the templates from the script side and the &lt;em&gt;include&lt;/em&gt; directive. Similar solution can be found in OPT 1.x, however in the new version, it should be forgotten - unless we use the quirks mode, the parser does not let us to call the &lt;em&gt;parse()&lt;/em&gt; method more than once. In the beginning, I planned to replace it by extending inclusion with &quot;sequences&quot; - a groups of templates to include with their own variables and cache settings. However, one day I was asked on my blog by Coldpeer, whether OPT will support template inheritance. I googled for a while, I looked at it and thought it might be cool. That's how the implementation began.&lt;/p&gt;    &lt;p&gt;As far as I know, template inheritance appeared for the first time in the Python framework, Django. The idea is taken from the object oriented programming, where we can extend classes by adding new methods, fields and overwriting the existing ones. Here it looks similar. We have a main template where we mark some characteristic places and fill them with a default content. Another template extends the main one and is able to overwrite that places with its own content. There can go the next template, and next...&lt;/p&gt;


&lt;p&gt;I was quite surprised that a lot of required functionality already exists in OPT 1.x - the &lt;em&gt;bind&lt;/em&gt; and &lt;em&gt;insert&lt;/em&gt; instructions allowed to move whole template parts somewhere else (as well as their functionality, not only the result, like in Smarty's &lt;em&gt;capture&lt;/em&gt;), even if the destination was in the other template. Unfortunately, there was no proper detection, whether one of the files was modified, so unsually the parser decided that the main part needs to be compiled, but the template with snippet definitions - does not. As a result, the places remained empty, although they should not. The development of such system for OPT 2.0 was quite complicated. You do not have to check just the template you've called, whether it is modified. You must also look at all the templates it inherits. Yesterday, I decided to solve this problem definietly and a couple of hours ago everything seemed to work properly:&lt;/p&gt;


&lt;p&gt;The base template (&lt;em&gt;test_inherited_a.tpl&lt;/em&gt;):&lt;/p&gt;
&lt;pre name=&quot;code&quot; class=&quot;html&quot;&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot; standalone=&amp;quot;yes&amp;quot; ?&amp;gt;
&amp;lt;!DOCTYPE html PUBLIC &amp;quot;-//W3C//DTD XHTML 1.0 Transitional//EN&amp;quot;
	   &amp;quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&amp;quot;&amp;gt;

&amp;lt;html xmlns=&amp;quot;http://www.w3.org/1999/xhtml&amp;quot; lang=&amp;quot;en_US&amp;quot; xml:lang=&amp;quot;en_US&amp;quot;&amp;gt;
 &amp;lt;head&amp;gt;
  &amp;lt;title&amp;gt;Instruction test: snippet and insert&amp;lt;/title&amp;gt;
 &amp;lt;/head&amp;gt;
 &amp;lt;body&amp;gt;
  &amp;lt;opt:insert snippet=&amp;quot;header&amp;quot;&amp;gt;
   &amp;lt;h1&amp;gt;I'm a standard header&amp;lt;/h1&amp;gt;
   &amp;lt;p&amp;gt;Foo bar joe&amp;lt;/p&amp;gt;  
  &amp;lt;/opt:insert&amp;gt;
  
  &amp;lt;hr/&amp;gt;
  
  &amp;lt;opt:insert snippet=&amp;quot;content&amp;quot;&amp;gt;
  	&amp;lt;p&amp;gt;Well, i'm also a standard content.&amp;lt;/p&amp;gt;
  
  &amp;lt;/opt:insert&amp;gt;
  
  &amp;lt;hr/&amp;gt;
  
  &amp;lt;opt:insert snippet=&amp;quot;footer&amp;quot;&amp;gt;
  	&amp;lt;p&amp;gt;And I'm a footer.&amp;lt;/p&amp;gt;  
  &amp;lt;/opt:insert&amp;gt;
  
  &amp;lt;p&amp;gt;&amp;amp;copy; Pasteright 2008 by LMAO, It seems to work!&amp;lt;/p&amp;gt;
 &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/pre&gt;


&lt;p&gt;The extending template (&lt;em&gt;test_inherit_1.tpl&lt;/em&gt;):&lt;/p&gt;

&lt;pre name=&quot;code&quot; class=&quot;xml&quot;&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot; standalone=&amp;quot;yes&amp;quot; ?&amp;gt;
&amp;lt;opt:extend file=&amp;quot;test_inherited_a.tpl&amp;quot;&amp;gt;
	&amp;lt;opt:snippet name=&amp;quot;header&amp;quot;&amp;gt;
		&amp;lt;h1&amp;gt;Webmaster Of Puppets&amp;lt;/h1&amp;gt;
	&amp;lt;/opt:snippet&amp;gt;

	&amp;lt;opt:snippet name=&amp;quot;content&amp;quot;&amp;gt;
		&amp;lt;p&amp;gt;Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Phasellus ut tellus id nulla adipiscing eleifend. Sed dictum accumsan ante. Nullam at nisl vitae elit aliquet fringilla. Praesent egestas eros eget tellus. Praesent id odio a sapien rhoncus vehicula. Nunc fringilla, diam eget euismod tempor, tortor metus tincidunt sapien, eu cursus magna tellus at risus. Praesent non tellus eget magna facilisis pulvinar. Praesent libero mi, adipiscing a, pharetra eget, condimentum sodales, mi. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos hymenaeos. Donec ac elit. Duis iaculis tortor a metus. Aliquam id purus et eros faucibus fringilla. Praesent quis quam. In lectus urna, fringilla sit amet, iaculis eget, aliquet ac, quam. Donec vulputate dui sit amet lectus. Aenean tempor, orci at pretium ornare, tortor tortor venenatis ligula, eget blandit nisi risus eget dolor. Duis nunc neque, sodales porta, viverra non, tristique eu, sem. Curabitur magna neque, blandit ullamcorper, congue quis, tristique ut, felis.&amp;lt;/p&amp;gt;
	&amp;lt;/opt:snippet&amp;gt;

	&amp;lt;opt:snippet name=&amp;quot;footer&amp;quot;&amp;gt;
		&amp;lt;p&amp;gt;Bye!!!&amp;lt;/p&amp;gt;
	&amp;lt;/opt:snippet&amp;gt;
&amp;lt;/opt:extend&amp;gt;
&lt;/pre&gt;


&lt;p&gt;Some PHP code:&lt;/p&gt;

&lt;pre name=&quot;code&quot; class=&quot;php&quot;&gt;&amp;lt;?php

	define('OPT_DIR', '../lib/');
	require(OPT_DIR.'opt.class.php');

	try
	{
		$tpl = new optClass;
		$tpl -&amp;gt; sourceDir = './templates/';
		$tpl -&amp;gt; compileDir = './templates_c/';
		$tpl -&amp;gt; stripWhitespaces = false;
		$tpl -&amp;gt; printComments = false;
		$tpl -&amp;gt; setup();
		
		$tpl -&amp;gt; parse('test_inherit_1.tpl');
	}
	catch(optException $e)
	{
		optErrorHandler($e);
	}
?&amp;gt;
&lt;/pre&gt;


&lt;p&gt;And the result can be admired below:&lt;/p&gt;


&lt;p&gt;&lt;a href=&quot;http://blog.invenzzia.org/public/images/template_inheritance.png&quot;&gt;&lt;img src=&quot;http://blog.invenzzia.org/public/images/.template_inheritance_m.jpg&quot; alt=&quot;Template inheritance&quot; style=&quot;display:block; margin:0 auto;&quot; /&gt;&lt;/a&gt;&lt;/p&gt;


&lt;p&gt;Some facts:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;If we modify any of the templates in the inheritance chain, the parser will notice it and recompile proper files.&lt;/li&gt;
&lt;li&gt;If we remove any of &quot;opt:snippet&quot; instructions, the default content of &quot;opt:insert&quot; will be displayed.&lt;/li&gt;
&lt;li&gt;There is a possibility to overwrite an existing snippet by the more important template. You will be also able to call the parent content, however it is not implemented yet (some kind of &quot;opt:parent&quot; instruction).&lt;/li&gt;
&lt;li&gt;It can be mixed with &quot;opt:include&quot; and &quot;opt:sequence&quot; (the sequence system briefly mentioned in the introduction).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;What is more, it's quite possible that the template inheritance will work faster than traditional way, although it will consume more disk space. Simply, if we have an inheritance like this: &quot;A extends  B extends C&quot;, the compiler puts all their code in the file belonging to the &quot;A&quot; template. It reduces the amount of disk operations (the execution of one bigger template is faster than the same content in five files). On the other hand, by default OPT still checks the file modification times, but fortunately, the number of tests is also smaller. The exact results will be available, when some benchmarks are done. Before we end, I'll say that two days ago I made a small test (a simple list with 15 items). The result:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;OPT 1.x: 1850 req/s&lt;/li&gt;
&lt;li&gt;OPT 2.0: 2100 req/s&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Well, it looks promising, but we have to remember that the new &lt;em&gt;opt.class.php&lt;/em&gt; file still does not have half of the options, which obviously will increase its size. Moreover, some optimizations are not implemented yet. But in fact, you can assume that the new features should not destroy the performance, and there is a chance that it will be even better.&lt;/p&gt;</description>
    
    
    
          <comments>http://blog.invenzzia.org/en/post/Template-inheritance#comment-form</comments>
      <wfw:comment>http://blog.invenzzia.org/en/post/Template-inheritance#comment-form</wfw:comment>
      <wfw:commentRss>http://blog.invenzzia.org/en/feed/rss2/comments/6</wfw:commentRss>
      </item>
    
</channel>
</rss>