d:\wwwroot\wuchunhua\smarty\SMARTY_2_BC_NOTES.txt

001: = Known incompatibilities with Smarty 2 =
002:
003: == Syntax ==
004:
005: Smarty 3 API has a new syntax. Much of the Smarty 2 syntax is supported
006: by a wrapper but deprecated. See the README that comes with Smarty 3 for more
007: information.
008:
009: The {$array|@mod} syntax has always been a bit confusing, where an "@" is required
010: to apply a modifier to an array instead of the individual elements. Normally you
011: always want the modifier to apply to the variable regardless of its type. In Smarty 3,
012: {$array|mod} and {$array|@mod} behave identical. It is safe to drop the "@" and the
013: modifier will still apply to the array. If you really want the modifier to apply to
014: each array element, you must loop the array in-template, or use a custom modifier that
015: supports array iteration. Most smarty functions already escape values where necessary
016: such as {html_options}
017:
018: == PHP Version ==
019: Smarty 3 is PHP 5 only. It will not work with PHP 4.
020:
021: == {php} Tag ==
022: The {php} tag is disabled by default. The use of {php} tags is
023: deprecated. It can be enabled with $smarty->allow_php_tag=true.
024:
025: But if you scatter PHP code which belongs together into several
026: {php} tags it may not work any longer.
027:
028: == Delimiters and whitespace ==
029: Delimiters surrounded by whitespace are no longer treated as Smarty tags.
030: Therefore, { foo } will not compile as a tag, you must use {foo}. This change
031: Makes Javascript/CSS easier to work with, eliminating the need for {literal}.
032: This can be disabled by setting $smarty->auto_literal = false;
033:
034: == Unquoted Strings ==
035: Smarty 2 was a bit more forgiving (and ambiguous) when it comes to unquoted strings
036: in parameters. Smarty3 is more restrictive. You can still pass strings without quotes
037: so long as they contain no special characters. (anything outside of A-Za-z0-9_)
038:
039: For example filename strings must be quoted
040: <source lang="smarty">
041: {include file='path/foo.tpl'}
042: </source>
043:
044: == Extending the Smarty class ==
045: Smarty 3 makes use of the __construct method for initialization. If you are extending
046: the Smarty class, its constructor is not called implicitly if the your child class defines
047: its own constructor. In order to run Smarty's constructor, a call to parent::__construct()
048: within your child constructor is required.
049:
050: <source lang="php">
051: class MySmarty extends Smarty {
052:    function __construct() {
053:        parent::__construct();
054:     
055:        // your initialization code goes here
056:
057:    }
058: }
059: </source>
060:
061: == Autoloader ==
062: Smarty 3 does register its own autoloader with spl_autoload_register. If your code has
063: an existing __autoload function then this function must be explicitly registered on
064: the __autoload stack. See http://us3.php.net/manual/en/function.spl-autoload-register.php
065: for further details.
066:
067: == Plugin Filenames ==
068: Smarty 3 optionally supports the PHP spl_autoloader. The autoloader requires filenames
069: to be lower case. Because of this, Smarty plugin file names must also be lowercase.
070: In Smarty 2, mixed case file names did work.
071:
072: == Scope of Special Smarty Variables ==
073: In Smarty 2 the special Smarty variables $smarty.section... and $smarty.foreach...
074: had global scope. If you had loops with the same name in subtemplates you could accidentally
075: overwrite values of parent template.
076:
077: In Smarty 3 these special Smarty variable have only local scope in the template which
078: is defining the loop. If you need their value in a subtemplate you have to pass them
079: as parameter.
080: <source lang="smarty">
081: {include file='path/foo.tpl' index=$smarty.section.foo.index}
082: </source>
083:
084: == SMARTY_RESOURCE_CHAR_SET ==
085: Smarty 3 sets the constant SMARTY_RESOURCE_CHAR_SET to utf-8 as default template charset.
086: This is now used also on modifiers like escape as default charset. If your templates use
087: other charsets make sure that you define the constant accordingly. Otherwise you may not
088: get any output.
089:
090: == newline at {if} tags ==
091: A \n was added to the compiled code of the {if},{else},{elseif},{/if} tags to get output of newlines as expected by the template source.
092: If one of the {if} tags is at the line end you will now get a newline in the HTML output.
093:
094: == trigger_error() ==
095: The API function trigger_error() has been removed because it did just map to PHP trigger_error.
096: However it's still included in the Smarty2 API wrapper.
097:
098: == Smarty constants ==
099: The constants
100: SMARTY_PHP_PASSTHRU
101: SMARTY_PHP_QUOTE
102: SMARTY_PHP_REMOVE
103: SMARTY_PHP_ALLOW
104: have been replaced with class constants
105: Smarty::PHP_PASSTHRU
106: Smarty::PHP_QUOTE
107: Smarty::PHP_REMOVE
108: Smarty::PHP_ALLOW
109:
110: