library/smarty/SMARTY_2_BC_NOTES.txt
author Markus Bröker <broeker.markus@googlemail.com>
Thu, 12 Nov 2015 14:39:16 +0100
changeset 0 4869aea77e21
permissions -rw-r--r--
Bröker-Framework BFW-1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
     1
= Known incompatibilities with Smarty 2 =
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
     2
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
     3
== Syntax ==
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
     4
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
     5
Smarty 3 API has a new syntax. Much of the Smarty 2 syntax is supported 
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
     6
by a wrapper but deprecated. See the README that comes with Smarty 3 for more 
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
     7
information.
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
     8
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
     9
The {$array|@mod} syntax has always been a bit confusing, where an "@" is required
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    10
to apply a modifier to an array instead of the individual elements. Normally you
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    11
always want the modifier to apply to the variable regardless of its type. In Smarty 3,
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    12
{$array|mod} and {$array|@mod} behave identical. It is safe to drop the "@" and the
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    13
modifier will still apply to the array. If you really want the modifier to apply to
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    14
each array element, you must loop the array in-template, or use a custom modifier that
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    15
supports array iteration. Most smarty functions already escape values where necessary
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    16
such as {html_options}
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    17
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    18
== PHP Version ==
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    19
Smarty 3 is PHP 5 only. It will not work with PHP 4.
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    20
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    21
== {php} Tag ==
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    22
The {php} tag is disabled by default. The use of {php} tags is
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    23
deprecated. It can be enabled with $smarty->allow_php_tag=true.
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    24
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    25
But if you scatter PHP code which belongs together into several
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    26
{php} tags it may not work any longer.
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    27
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    28
== Delimiters and whitespace ==
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    29
Delimiters surrounded by whitespace are no longer treated as Smarty tags.
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    30
Therefore, { foo } will not compile as a tag, you must use {foo}. This change
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    31
Makes Javascript/CSS easier to work with, eliminating the need for {literal}.
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    32
This can be disabled by setting $smarty->auto_literal = false;
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    33
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    34
== Unquoted Strings ==
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    35
Smarty 2 was a bit more forgiving (and ambiguous) when it comes to unquoted strings 
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    36
in parameters. Smarty3 is more restrictive. You can still pass strings without quotes 
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    37
so long as they contain no special characters. (anything outside of A-Za-z0-9_) 
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    38
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    39
For example filename strings must be quoted
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    40
<source lang="smarty">
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    41
{include file='path/foo.tpl'}
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    42
</source>
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    43
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    44
== Extending the Smarty class ==
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    45
Smarty 3 makes use of the __construct method for initialization. If you are extending 
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    46
the Smarty class, its constructor is not called implicitly if the your child class defines 
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    47
its own constructor. In order to run Smarty's constructor, a call to parent::__construct() 
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    48
within your child constructor is required. 
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    49
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    50
<source lang="php">
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    51
class MySmarty extends Smarty {
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    52
   function __construct() {
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    53
       parent::__construct();
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    54
    
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    55
       // your initialization code goes here
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    56
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    57
   }
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    58
}
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    59
</source>
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    60
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    61
== Autoloader ==
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    62
Smarty 3 does register its own autoloader with spl_autoload_register. If your code has 
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    63
an existing __autoload function then this function must be explicitly registered on 
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    64
the __autoload stack. See http://us3.php.net/manual/en/function.spl-autoload-register.php 
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    65
for further details.
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    66
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    67
== Plugin Filenames ==
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    68
Smarty 3 optionally supports the PHP spl_autoloader. The autoloader requires filenames 
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    69
to be lower case. Because of this, Smarty plugin file names must also be lowercase. 
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    70
In Smarty 2, mixed case file names did work.
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    71
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    72
== Scope of Special Smarty Variables ==
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    73
In Smarty 2 the special Smarty variables $smarty.section... and $smarty.foreach... 
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    74
had global scope. If you had loops with the same name in subtemplates you could accidentally 
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    75
overwrite values of parent template.
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    76
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    77
In Smarty 3 these special Smarty variable have only local scope in the template which 
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    78
is defining the loop. If you need their value in a subtemplate you have to pass them 
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    79
as parameter.
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    80
<source lang="smarty">
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    81
{include file='path/foo.tpl' index=$smarty.section.foo.index}
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    82
</source>
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    83
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    84
== SMARTY_RESOURCE_CHAR_SET ==
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    85
Smarty 3 sets the constant SMARTY_RESOURCE_CHAR_SET to utf-8 as default template charset. 
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    86
This is now used also on modifiers like escape as default charset. If your templates use 
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    87
other charsets make sure that you define the constant accordingly. Otherwise you may not 
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    88
get any output.
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    89
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    90
== newline at {if} tags ==
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    91
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. 
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    92
If one of the {if} tags is at the line end you will now get a newline in the HTML output.
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    93
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    94
== trigger_error() ==
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    95
The API function trigger_error() has been removed because it did just map to PHP trigger_error.
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    96
However it's still included in the Smarty2 API wrapper.
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    97
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    98
== Smarty constants ==
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
    99
The constants 
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
   100
SMARTY_PHP_PASSTHRU
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
   101
SMARTY_PHP_QUOTE
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
   102
SMARTY_PHP_REMOVE
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
   103
SMARTY_PHP_ALLOW
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
   104
have been replaced with class constants
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
   105
Smarty::PHP_PASSTHRU
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
   106
Smarty::PHP_QUOTE
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
   107
Smarty::PHP_REMOVE
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
   108
Smarty::PHP_ALLOW
4869aea77e21 Bröker-Framework BFW-1
Markus Bröker <broeker.markus@googlemail.com>
parents:
diff changeset
   109