From 54bf2945c8240afd0d273fb0beae11a0b10943f5 Mon Sep 17 00:00:00 2001 From: mohrt Date: Fri, 26 Jan 2001 17:47:59 +0000 Subject: [PATCH] update again --- AUTHORS | 1 + Config_File.class.php | 2 +- FAQ | 3 + NEWS | 1 + README | 6 +- Smarty.addons.php | 2 +- demo/templates/index.tpl | 11 +-- docs.sgml | 190 +++++++++++++++++++++++++++---------- libs/Config_File.class.php | 2 +- templates/index.tpl | 11 +-- 10 files changed, 163 insertions(+), 66 deletions(-) diff --git a/AUTHORS b/AUTHORS index 367859e9..dc795bec 100644 --- a/AUTHORS +++ b/AUTHORS @@ -5,3 +5,4 @@ Monte Ohrt Andrei Zmievski - Rewrote parser from scratch - added much other functionality + - wrote Config_File class diff --git a/Config_File.class.php b/Config_File.class.php index be61190f..8367c34f 100644 --- a/Config_File.class.php +++ b/Config_File.class.php @@ -5,7 +5,7 @@ require_once "PEAR.php"; /** * Config_File class. * - * @version 1.0 + * @version 1.2.0 * @author Andrei Zmievski * @access public * diff --git a/FAQ b/FAQ index 4018ebd4..f5d5a1ac 100644 --- a/FAQ +++ b/FAQ @@ -23,6 +23,9 @@ A: What this means is that Smarty reads the template files and creates PHP automatically by Smarty. Template designers never need to mess with the generated PHP scripts or even know of their existance. +Q: Do you have a mailing list? +A: Yes. Subscribe by sending an e-mail to subscribe-smarty@lists.ispi.net + TROUBLESHOOTING --------------- diff --git a/NEWS b/NEWS index 9ea363cd..958d5186 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,6 @@ Version 1.2.0 ------------- + - updated documentation (Monte) - added file and line number information to syntax error messages. (Andrei) - added ability to index template vars by a key. (Andrei) diff --git a/README b/README index 9d1d48de..a4673d57 100644 --- a/README +++ b/README @@ -2,7 +2,7 @@ NAME: Smarty - the PHP compiling template engine -VERSION: 1.1.0 +VERSION: 1.2.0 AUTHORS: @@ -48,6 +48,10 @@ DESCRIPTION: although not recommended and doubtfully needed since the engine is so customizable. +MAILING LIST: + We have a mailing list for you to share your ideas or ask questions. + send a blank e-mail message to subscribe-smarty@lists.ispi.net + COPYRIGHT: Copyright (c) 2001 ispi of Lincoln, Inc. All rights reserved. This software is released under the GNU General Public License. diff --git a/Smarty.addons.php b/Smarty.addons.php index 145259ee..683ea66d 100644 --- a/Smarty.addons.php +++ b/Smarty.addons.php @@ -5,7 +5,7 @@ * File: Smarty.addons.php * Author: Monte Ohrt * Andrei Zmievski - * Version: 1.1.0 + * Version: 1.2.0 * Copyright: 2001 ispi of Lincoln, Inc. * * This program is free software; you can redistribute it and/or diff --git a/demo/templates/index.tpl b/demo/templates/index.tpl index 08f73665..dd9d0b93 100644 --- a/demo/templates/index.tpl +++ b/demo/templates/index.tpl @@ -24,17 +24,14 @@ My interests are: none {/section} -testing +testing section looped key values
{section name=sec1 loop=$contacts} - phone: {$sec1/contacts.phone} - fax: {$sec1/contacts.fax} - cell: {$sec1/contacts.cell} + phone: {$sec1/contacts.phone}
+ fax: {$sec1/contacts.fax}
+ cell: {$sec1/contacts.cell}
{/section} -

-{%^^^} - testing strip tags {strip} diff --git a/docs.sgml b/docs.sgml index 95dfe42f..b099f120 100644 --- a/docs.sgml +++ b/docs.sgml @@ -14,7 +14,7 @@
andrei@ispi.net
- Version 1.1.0 + Version 1.2.02001ispi of Lincoln, Inc. @@ -459,7 +459,8 @@ $output = $smarty->fetch("./templates/index.tpl"); like so: {$varname} -Template example of displaying assigned variables + +displaying assigned variables Hello {$firstname}, glad to see you could make it. @@ -473,12 +474,38 @@ Hello Doug, glad to see you could make it. Your last login was on January 11th, 2001. - - There are also variables within looping sections that are displayed - a bit differently. Those are exaplained later in this document under - Built-in Functions. - + + + Associative arrays + + You can also print variables that are assigned as associative + arrays from PHP by supplying the key value with the array name. + + +displaying assigned associative array variables + + +{$Contacts.fax}<br> +{$Contacts.email}<br> +{* you can print arrays of arrays as well *} +{$Contacts.phone.home}<br> +{$Contacts.phone.cell}<br> + +OUTPUT: + +555-222-9876<br> +zaphod@slartibartfast.com<br> +555-444-3333<br> +555-111-1234<br> + + + + + + + + Variables passed from config files @@ -487,7 +514,9 @@ Your last login was on January 11th, 2001. like so: {#varname#} -Template example of displaying config variables + + +displaying config variables <html> @@ -529,7 +558,7 @@ Your last login was on January 11th, 2001. attributes into delimiters like so: {funcname attr1="val" attr2="val"} -Template example of function syntax +function syntax {config_load file="colors.conf"} @@ -560,7 +589,7 @@ Your last login was on January 11th, 2001. also be used, and should not be in quotes. -Template example of function attribute syntax +function attribute syntax {include file="header.tpl"} @@ -584,7 +613,7 @@ Your last login was on January 11th, 2001. They are used mainly for making the templates more understandable. -Template example of Comments +Comments {* Smarty *} @@ -678,7 +707,7 @@ Intro = """This is a value that spans more See Config Files for more info. -Template example of function config_load +function config_load {config_load file="colors.conf"} @@ -703,7 +732,7 @@ Intro = """This is a value that spans more "section". -Template example of function config_load with section +function config_load with section {config_load file="colors.conf" section="Customer"} @@ -734,7 +763,7 @@ Intro = """This is a value that spans more to the template directory. -Template example of function include +function include {include file="header.tpl"} @@ -754,7 +783,7 @@ Intro = """This is a value that spans more static values since variables are inherited anyways). -Template example of function include passing variables +function include passing variables {include file="header.tpl" title="Main Menu" table_bgcolor="#c0c0c0"} @@ -784,7 +813,7 @@ Intro = """This is a value that spans more and needs to call a function to get the banner's contents. -Template example of function insert +function insert {* example of fetching a banner *} @@ -825,7 +854,7 @@ Intro = """This is a value that spans more "<","<=",">=" are all valid conditional qualifiers. -Template example of if statements +if statements {if $name eq "Fred"} @@ -894,7 +923,7 @@ Intro = """This is a value that spans more delimiters, so this is the way around that. -Template example of ldelim, rdelim +ldelim, rdelim {* this will print literal delimiters out of the template *} @@ -919,7 +948,7 @@ OUTPUT: interpreted, but displayed as-is. -Template example of literal tags +literal tags {literal} @@ -958,7 +987,7 @@ OUTPUT: variable. -example: section +section @@ -977,7 +1006,7 @@ id: 1002<br> -example: section loop variable +section loop variable {* the loop variable only determines the number of times to loop. @@ -1011,7 +1040,7 @@ address: 5605 apple st -example: section names +section names {* the name of the section can be anything you like, @@ -1027,7 +1056,7 @@ address: 5605 apple st -example: nested sections +nested sections {* sections can be nested as deep as you like. With nested sections, @@ -1074,7 +1103,42 @@ e-mail: jane@mydomain.com -example: sectionelse +sections and associative arrays + + +{* This is an example of printing an associative array + of data within a section *} +{section name=customer loop=$contacts} + {$customer/contacts.name}<br> + {$customer/contacts.home}<br> + {$customer/contacts.cell}<br> + {$customer/contacts.email}<br> +{/section} + + +OUTPUT: + +name: John Smith<br> +home: 555-555-5555<p> +cell: 555-555-5555<p> +e-mail: john@mydomain.com<p> +name: Jack Jones<br> +home phone: 555-555-5555<p> +cell phone: 555-555-5555<p> +e-mail: jack@mydomain.com<p> +name: Jane Munson<p> +home phone: 555-555-5555<p> +cell phone: 555-555-5555<p> +e-mail: jane@mydomain.com<p> + + + + + + + + +sectionelse {* sectionelse will execute in the case there are no $custid values *} @@ -1098,7 +1162,7 @@ e-mail: jane@mydomain.com starting with zero. -example: section property index +section property index {section name=customer loop=$custid} {%customer.index%} id: {$customer/custid}<br> @@ -1121,7 +1185,7 @@ OUTPUT: starting with one. -example: section property rownum +section property rownum {section name=customer loop=$custid} {%customer.rownum%} id: {$customer/custid}<br> @@ -1145,7 +1209,7 @@ OUTPUT: inside or after the section. -example: section property index +section property index {section name=customer loop=$custid} {%customer.index%} id: {$customer/custid}<br> @@ -1175,7 +1239,7 @@ There were 3 customers shown above. displayed. -example: section property rownum +section property rownum {* $show_customer_info may have been passed from the PHP application, to regulate whether or not this section shows *} @@ -1220,7 +1284,7 @@ the section was shown. about extra white space causing problems. -Template example of strip tags +strip tags {* the following will be all run into one line upon output *} @@ -1266,7 +1330,7 @@ OUTPUT: selected by default as well. -Template example of html_options +html_options {* assume that $cust_ids, and $cust_names are arrays of values, @@ -1313,7 +1377,7 @@ OUTPUT: year_as_text, boolean, true -Template example of html_select_date +html_select_date {html_select_date} @@ -1377,7 +1441,7 @@ OUTPUT: -Template example of html_select_date +html_select_date @@ -1447,7 +1511,7 @@ OUTPUT: these are by example. -Template example of variable modifiers +variable modifiers {* this displays a variable, unmodified *} @@ -1733,24 +1797,54 @@ is the first week that has at least 4 days in the current year, and with Monday Smarty/PHP errors - As of now, Smarty is not a validating template parser. This means that - the parser will blindly convert the template to PHP scripts, - irregardless of any syntax errors in the markup tags that may be - present in the template. Smarty can catch certain template errors like - missing attributes to functions, but not syntax errors like missing + Smarty can catch many errors such as missing tag attributes + or malformed variable names. If this happens, you will see an error + similar to the following: + + + +Smarty errors + + +Warning: Smarty: [in index.tpl line 4]: syntax error: unknown tag - '%blah' + in /path/to/smarty/Smarty.class.php on line 1041 + +Fatal error: Smarty: [in index.tpl line 28]: syntax error: missing section name + in /path/to/smarty/Smarty.class.php on line 1041 + + + + + + Smarty shows you the template name, the line number and the error. + Everything beyond that is PHP error messages which you can ignore. + + + + There are certain errors that Smarty cannot catch, such as missing close tags. These types of errors can end up in PHP compile-time - errors. When you encounter a PHP error when attempting to display the + errors. + + + +PHP errors + + +Parse error: parse error in /path/to/smarty/templates_c/index.tpl.php on line 75 + + + + + + When you encounter a PHP error when attempting to display the template in a browser, the error line number will correspond to the compiled PHP script, not the template itself. This may be a bit - confusing or for the template designer. Our experience is to tell the - designers to check their work often, and ask the programmers for help - if they are really stuck. Usually you can look at the template and spot - the syntax error. Here are some common things to look for: missing - close tags for {if}{/if} or {section}{/section}, missing end variable - delimiters like {%sec.var} instead of {%sec.var%}, or {#var} instead of - {#var#}. If you can't find the error, you must open the compiled PHP - file and go to the line number to figure out where the corresponding - error is in the template. + confusing. Usually you can look at the template and spot the syntax + error. Here are some common things to look for: missing close tags for + {if}{/if} or {section}{/section}, or syntax of logic within an {if} + tag. If you can't find the error, you must open the compiled PHP file + and go to the line number to figure out where the corresponding error + is in the template. diff --git a/libs/Config_File.class.php b/libs/Config_File.class.php index be61190f..8367c34f 100644 --- a/libs/Config_File.class.php +++ b/libs/Config_File.class.php @@ -5,7 +5,7 @@ require_once "PEAR.php"; /** * Config_File class. * - * @version 1.0 + * @version 1.2.0 * @author Andrei Zmievski * @access public * diff --git a/templates/index.tpl b/templates/index.tpl index 08f73665..dd9d0b93 100644 --- a/templates/index.tpl +++ b/templates/index.tpl @@ -24,17 +24,14 @@ My interests are: none {/section} -testing +testing section looped key values
{section name=sec1 loop=$contacts} - phone: {$sec1/contacts.phone} - fax: {$sec1/contacts.fax} - cell: {$sec1/contacts.cell} + phone: {$sec1/contacts.phone}
+ fax: {$sec1/contacts.fax}
+ cell: {$sec1/contacts.cell}
{/section} -

-{%^^^} - testing strip tags {strip}