Page title
-H2O template inheritance is a powerful tool
- {% endblock %} -diff --git a/README.md b/README.md
index d7d7acc..2153949 100644
--- a/README.md
+++ b/README.md
@@ -14,8 +14,8 @@ __Features__
* Easy to use and maintain
* Encourages reuse in templates by allowing template inclusion and inheritance.
* Highly extensible through filters, tags, and template extensions.
- * Includes a rich set of filters and tags for string formatting, HTML helpers and
- internationalization support.
+ * Includes a rich set of filters and tags for string formatting, HTML helpers and
+ internationalization support.
Requirement
@@ -27,15 +27,15 @@ Requirement
News
------------------------
- - version 0.4
- 1. **Breaking changes** autoescape is now turned on by default
- 2. Improved searchpath and file loading handling
- 3. Improved handling on PHP overloaded objects
- 4. Plenty of bug fixes
+ - version 0.4
+ 1. **Breaking changes** autoescape is now turned on by default
+ 2. Improved searchpath and file loading handling
+ 3. Improved handling on PHP overloaded objects
+ 4. Plenty of bug fixes
- version 0.3
- 1. Support internationalized templates and translation parsing toolkit
- 2. Performance optimization on context lookup
- 3. Fixed operator parsing
+ 1. Support internationalized templates and translation parsing toolkit
+ 2. Performance optimization on context lookup
+ 3. Fixed operator parsing
Getting started
------------------------
@@ -45,47 +45,47 @@ Getting started
Download
[
](http://code.google.com/p/h2o-template/downloads)
-
+
With Git
`git clone http://github.com/speedmax/h2o-php.git`
-With SVN
+With SVN
`svn checkout http://h2o-template.googlecode.com/svn/trunk/ h2o`
### Installation
1. Download and extract h2o into your project path or your php include path
- Sample file structure setup
-
- myawesome_app/
- index.php
- templates/
- index.html
- h2o/
+ Sample file structure setup
+
+ myawesome_app/
+ index.php
+ templates/
+ index.html
+ h2o/
2. Use `require 'h2o/h2o.php'` in your php files to include the h2o library.
- 3. Below is a basic code sample to get your project going.
- 3. Check out the *\example* and *\specs* dirs to see some of h2o's more interesting features in action.
-
+ 3. Below is a basic code sample to get your project going.
+ 3. Check out the *\example* and *\specs* dirs to see some of h2o's more interesting features in action.
+
*templates/index.html*
-
H2O template inheritance is a powerful tool
- {% endblock %} -H2O template inheritance is a powerful tool
+ {% endblock %} +Body of extended page
- {% endblock %} - - {% block sidebar %} - Sidebar contains use links. - {% endblock %} + {% extends 'base.html' %} + + {% block content %} +Body of extended page
+ {% endblock %} + {% block sidebar %} + Sidebar contains use links. + {% endblock %} -The `page.html` extends `base.html`, allowing us to override any block -previously defined in `base.html`. + +The `page.html` extends `base.html`, allowing us to override any block +previously defined in `base.html`. Below is an excellent article about template inheritance in Django. If you wish to understand H2o's -template-inheritance system, this would be a great spot to start, since H2o's template-inheritance system +template-inheritance system, this would be a great spot to start, since H2o's template-inheritance system is strongly influenced by Django's. -[Power of inheritance][3] is a very good blog post explaining inheritance +[Power of inheritance][3] is a very good blog post explaining inheritance [3]:http://www2.jeffcroft.com/blog/2006/feb/25/django-templates-the-power-of-inheritance/ *Tips* -* If you have found that you have several common elements inside the same template, it may be a - good idea to put that portion of the template inside a `block` in a base template. +* If you have found that you have several common elements inside the same template, it may be a + good idea to put that portion of the template inside a `block` in a base template. * `block` give you a hook, which is useful, since these can help with javascript and css too. * When defining a block use a short and distinctive name @@ -281,11 +281,11 @@ is strongly influenced by Django's. ### Configuration There are a range of options for configuring the template engine. - [option_value] - )); - ?> + [option_value] + )); + ?> #### Loader The name of the loader or an instance of H2o_Loader @@ -296,28 +296,28 @@ __Use file loader [default]__ __Advanced setup__ - $loader ); - ?> - + $loader ); + ?> + __Use dictionary loader__ If you want to load templates from resources other than files, then this will be your friend. H2o uses `dict_loader()` for testing. - 'Hello {{ person }}' - )); - $template = new H2o('index.html', array('loader' => $loader')); - ?> + 'Hello {{ person }}' + )); + $template = new H2o('index.html', array('loader' => $loader')); + ?> #### Searchpath default: this will be the base path of your template -H2o use this path to load additional templates and extensions. +H2o use this path to load additional templates and extensions. You can either explicity set the search path, @@ -328,7 +328,7 @@ or h2o will try to find the searchpath for you. `$template = new H2o('/sites/common_templates/index.html');` #### Cache -You can define the type of caching engine h2o should use, if any. +You can define the type of caching engine h2o should use, if any. Set 'cache' to false to disable caching. You can read more about performance and caching in following sections @@ -349,7 +349,7 @@ Disable caching `$template = new H2o('index.html', array('cache'=>false));` #### Cache_dir -When the file cache is used, you can define where you want templates to be cached. +When the file cache is used, you can define where you want templates to be cached. It will put a cached template in same location as the normal template @@ -365,28 +365,28 @@ that is bundled in the cache extension will use this as default ttl value. Performance and Caching ------------------------ -Caching can increase performance since it skips step of inefficient template parsing. +Caching can increase performance since it skips step of inefficient template parsing. H2o caches the template objects (the internal data structure of a template) and the bundled caching backends include File, APC, and Memcache. ### File cache -By default h2o uses the file cache to store template objects. Change h2o option `cache_dir` to where you +By default h2o uses the file cache to store template objects. Change h2o option `cache_dir` to where you want to store template cache (ie: /tmp). - - 'file', - 'cache_dir' => '/tmp' - )); - ?> + + 'file', + 'cache_dir' => '/tmp' + )); + ?> ### APC cache -APC is an op-code and object cache extension for php whose performance is -generally 10-30% better than just plain file caching. +APC is an op-code and object cache extension for php whose performance is +generally 10-30% better than just plain file caching. - 'apc')); - ?> + 'apc')); + ?> ### Memcache Currently not implemented @@ -399,25 +399,25 @@ Extending H2o Known issues ------------------------ Yes, h2o has them. However, if you are careful, these shouldn't hinder your template development. -The deep inheritance issue is a bit problematic for some template architectures, but again, if you +The deep inheritance issue is a bit problematic for some template architectures, but again, if you are careful, and perhaps a bit inventive, it won't hinder you terribly much. * `{{ block.super }}` doesn't work with more than 1 level of inheritance yet, so if `{{ block.super }}` - invokes another `{{ block.super }}` it won't work just yet. - * 'if' conditions don't support multiple expressions or mathematical expressions yet, like: - `{% if something > 3 or something < 2 %}` or `{% if something + else > 12 %}` - These likely will not be implemented in the future unless some daring soul implements them and - contributes the code back to the h2o-php project. - + invokes another `{{ block.super }}` it won't work just yet. + * 'if' conditions don't support multiple expressions or mathematical expressions yet, like: + `{% if something > 3 or something < 2 %}` or `{% if something + else > 12 %}` + These likely will not be implemented in the future unless some daring soul implements them and + contributes the code back to the h2o-php project. + Contributors --- - - - jlogsdon - Major refactoring (wip) and bug fixes - - cyberklin - Added filter support for any context resolve - - idlesign - Added if_changed tag support - - metropolis - Improved our test coverage - - plus many others + + - jlogsdon - Major refactoring (wip) and bug fixes + - cyberklin - Added filter support for any context resolve + - idlesign - Added if_changed tag support + - metropolis - Improved our test coverage + - plus many others Credit @@ -432,7 +432,7 @@ Special Thanks: Armin Ronacher, since early versions of h2o were based off of hi The MIT License ------------------------ -Copyright (c) 2008 Taylor Luk +Copyright (c) 2008 Taylor Luk Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/example/README.md b/example/README.md index 54b4b31..021a4a6 100644 --- a/example/README.md +++ b/example/README.md @@ -4,7 +4,7 @@ This directory contains example code covering various aspect of h2o template. Simple ===================== -A simple template displaying a list of users, it demonstrate +A simple template displaying a list of users, it demonstrate - how to setup h2o template and pass view variables to template - display variables and using build-in tags and filters @@ -33,11 +33,11 @@ Demonstrates - how to use different cache driver - bundled cache extension to provide fragment cache to speed up resource intensive operations - such as loading complex logic from database + such as loading complex logic from database I18n ===================== -Demo to show how to build a internationalized template with h2o by displaying a template +Demo to show how to build a internationalized template with h2o by displaying a template supporting three languages. I18n extension also bundled message extraction class to extract translatable strings into diff --git a/example/caching/index.php b/example/caching/index.php index 21dc8fd..5d44cd4 100644 --- a/example/caching/index.php +++ b/example/caching/index.php @@ -5,7 +5,7 @@ //// Set language to German //$i18n = new H2o_I18n(dirname(__FILE__).DS, array( -// 'gettext_path' => dirname(__FILE__).DS.'bin/gettext/bin/' +// 'gettext_path' => dirname(__FILE__).DS.'bin/gettext/bin/' //)); //$i18n->setLocale('fr'); // @@ -14,40 +14,40 @@ //// // Choose domain //extract_translations( -// realpath('trans.tpl'), array('tpl', 'html'), dirname(__FILE__).DS.'bin/gettext/bin/' +// realpath('trans.tpl'), array('tpl', 'html'), dirname(__FILE__).DS.'bin/gettext/bin/' //); // //compile_translations( -// realpath('trans.tpl'), null, dirname(__FILE__).DS.'bin/gettext/bin/' +// realpath('trans.tpl'), null, dirname(__FILE__).DS.'bin/gettext/bin/' //); - + $template = new H2o('trans.tpl', array('cache'=> false, 'cache_dir' => dirname(__FILE__))); $time_start = microtime(true); for($i=0; $i<10; $i++) $r = $template->render(array( - 'users' => array( - array( - 'username' => 'peter', - 'tasks' => array('school', 'writing'), - 'user_id' => 1, - ), - array( - 'username' => 'anton', - 'tasks' => array('go shopping'), - 'user_id' => 2, - ), - array( - 'username' => 'john doe', - 'tasks' => array('write report', 'call tony', 'meeting with arron'), - 'user_id' => 3 - ), - array( - 'username' => 'foobar', - 'tasks' => array(), - 'user_id' => 4 - ) - ) + 'users' => array( + array( + 'username' => 'peter', + 'tasks' => array('school', 'writing'), + 'user_id' => 1, + ), + array( + 'username' => 'anton', + 'tasks' => array('go shopping'), + 'user_id' => 2, + ), + array( + 'username' => 'john doe', + 'tasks' => array('write report', 'call tony', 'meeting with arron'), + 'user_id' => 3 + ), + array( + 'username' => 'foobar', + 'tasks' => array(), + 'user_id' => 4 + ) + ) )); echo $r; diff --git a/example/extensions/ext/site_tags.php b/example/extensions/ext/site_tags.php index eedba6a..9f92760 100644 --- a/example/extensions/ext/site_tags.php +++ b/example/extensions/ext/site_tags.php @@ -1,9 +1,9 @@ write('This is my site'); - } + function render($context, $stream) { + $stream->write('This is my site'); + } } diff --git a/example/i18n/index.php b/example/i18n/index.php index d56987e..eae1537 100644 --- a/example/i18n/index.php +++ b/example/i18n/index.php @@ -2,14 +2,14 @@ require '../../h2o.php'; $template = new H2o('trans.html', array( - 'cache'=> false, - 'i18n' => array( - 'locale' => isset($_GET['lang']) ? $_GET['lang'] : false, - 'charset' => 'UTF-8', - 'gettext_path' => '../bin/gettext/bin/', - 'extract_message' => true, - 'compile_message' => true, - ) + 'cache'=> false, + 'i18n' => array( + 'locale' => isset($_GET['lang']) ? $_GET['lang'] : false, + 'charset' => 'UTF-8', + 'gettext_path' => '../bin/gettext/bin/', + 'extract_message' => true, + 'compile_message' => true, + ) )); # Setup custom gettext resolver @@ -18,28 +18,28 @@ $time_start = microtime(true); echo $template->render(array( - 'users' => array( - array( - 'username' => 'peter', - 'tasks' => array('school', 'writing'), - 'user_id' => 1, - ), - array( - 'username' => 'anton', - 'tasks' => array('go shopping'), - 'user_id' => 2, - ), - array( - 'username' => 'john doe', - 'tasks' => array('write report', 'call tony', 'meeting with arron'), - 'user_id' => 3 - ), - array( - 'username' => 'foobar', - 'tasks' => array(), - 'user_id' => 4 - ) - ) + 'users' => array( + array( + 'username' => 'peter', + 'tasks' => array('school', 'writing'), + 'user_id' => 1, + ), + array( + 'username' => 'anton', + 'tasks' => array('go shopping'), + 'user_id' => 2, + ), + array( + 'username' => 'john doe', + 'tasks' => array('write report', 'call tony', 'meeting with arron'), + 'user_id' => 3 + ), + array( + 'username' => 'foobar', + 'tasks' => array(), + 'user_id' => 4 + ) + ) )); echo "in ".(microtime(true) - $time_start)." seconds\n+
{% blocktrans %} - (software engineering) The act or process of making a product suitable for - international markets, typically by making text messages easily translatable - and ensuring support of non-Latin character sets. + (software engineering) The act or process of making a product suitable for + international markets, typically by making text messages easily translatable + and ensuring support of non-Latin character sets. {% endblocktrans %}
@@ -28,29 +28,29 @@+
{% blocktrans count=users.length %} - there is one {{ count }} item. + there is one {{ count }} item. {% plural %} - there are number of {{ count }} items. + there are number of {{ count }} items. {% endblocktrans %}