Author: Raymond Bosman Date: 2007-05-04 16:51:20 +0200 (Fri, 04 May 2007) New Revision: 5057
Log: - Removed the 'old' tutorial. Next commit will replace this tutorial. Removed: trunk/Template/docs/tutorial.txt Deleted: trunk/Template/docs/tutorial.txt =================================================================== --- trunk/Template/docs/tutorial.txt 2007-05-04 14:49:02 UTC (rev 5056) +++ trunk/Template/docs/tutorial.txt 2007-05-04 14:51:20 UTC (rev 5057) @@ -1,157 +0,0 @@ -eZ Components - Template -~~~~~~~~~~~~~~~~~~~~~~~~ - -.. contents:: Table of Contents - -Introduction -============ - -The Template component, a template engine, provides a manageable way to separate -application logic from presentation data. The application logic is the PHP code -of your application, including the call to the Template component. Presentation -data refers to the templates files (containing the template code). - -The separation of application logic and presentation data not only makes the -parts easier to maintain, it also enables different people to work separately -on one of the parts. The template language was designed to be easy for -non-developers. - - -Class overview -============== - -The following list sums up the most important classes: - -ezcTemplate - This class provides the main API for processing templates. It - compiles the template to PHP code, executes it and returns the result. - -ezcTemplateConfiguration - This class configures the Template engine. Settings stored in this class - include: the location of the source templates; where to store the compiled - templates; and the type of context to use. - -ezcTemplateVariableCollection - The variables that should be sent to or retrieved from the template are - stored in an object of the type ezcTemplateVariableCollection. - -More information about these classes can be found in the class documentation. - - -Usage -===== - -The following examples demonstrate how to use the Template component. - -Getting started ---------------- - -The simplest example is to write "Hello world" to your -standard output. This consists of two steps: - -The first step is to create a text file "hello_world.ezt" that contains -only one line:: - - Hello world - -and store it in the directory where your application source resides. - -The next step is to use the following PHP script. - -.. include:: tutorial_simple.php - :literal: - -If you run your application, it should write "Hello world". If it doesn't, -check the following: - -- The base class can be found. Check "include_path" in the PHP.ini - settings, and see if the components are included. -- The template "hello_world.ezt" can be found. Write the absolute - path to your hello_world template in the "process" method. -- The template engine can write to the current directory. The next - section explains how another output directory can be specified. - -From now on, we assume that the template engine can be loaded and can locate -the template files. - - -Configuring the template engine -------------------------------- - -Templates are not always stored in your local directory, nor do you always -want to store the compiled templates among your source files. This can be -changed in the configuration: - -.. include:: tutorial_configuration.php - :literal: - -If you try to copy/paste and run this example, you will probably get the -following output:: - - Fatal error: Uncaught exception 'ezcTemplateFileNotFoundException' with message - 'The requested template file </usr/share/templates/hello_world.ezt> does not exist.' - -This error indicates that the template engine looks in the "/usr/share/templates" directory -for the templates. - -The ezcTemplate class calls the getInstance() method from the ezcTemplateConfiguration -class and retrieves the "default" configuration. It is possible to set multiple -configurations, which is demonstrated in the next example: - -.. include:: tutorial_multi_configuration.php - :literal: - -You would get the following output:: - - The requested template file <html/hello_world.ezt> does not exist. - - The requested template file <printer/hello_world.ezt> does not exist. - - The requested template file <pdf/hello_world.ezt> does not exist. - - -As demonstrated, the Template configuration can be set in the "configuration" -property, given as second parameter in the process method, or by using the "default" -getInstance configuration. - - -Setting and retrieving template variables ------------------------------------------ - -The following template code uses the variable $quote and returns the number -6. Copy/paste this example and save it as "send_receive.ezt". - -.. include:: tutorial_variable_send_receive.ezt - :literal: - -The template code that sends $quote and receives $number is as follows: - -.. include:: tutorial_variable_send_receive.php - :literal: - -The output for this template is:: - - You are number 6 - I am not a number, I am a free man. - - -More information -================ - -For more information, see the: - -* `Syntax documentation`_ -* `EBNF`_ -* `API documentation`_ - -.. _`Syntax documentation`: Template_syntax.html -.. _`EBNF`: Template_EBNF.html -.. _`API documentation`: classtrees_Template.html - - -.. - Local Variables: - mode: rst - fill-column: 79 - End: - vim: et syn=rst tw=79 -- svn-components mailing list svn-components@lists.ez.no http://lists.ez.no/mailman/listinfo/svn-components