Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

109 lines
4.4 KiB

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