Files
smarty/docs/getting-started.md

198 lines
5.7 KiB
Markdown
Raw Permalink Normal View History

2023-02-05 23:14:10 +01:00
# Getting started
## Requirements
Smarty can be run with PHP 7.2 to PHP 8.4.
## Installation
2023-02-05 23:14:10 +01:00
Smarty can be installed with [Composer](https://getcomposer.org/).
To get the latest stable version of Smarty use:
2023-02-05 23:14:10 +01:00
```shell
composer require smarty/smarty
2023-02-05 23:14:10 +01:00
```
To get the latest, unreleased version, use:
2023-02-05 23:14:10 +01:00
```shell
composer require smarty/smarty:dev-master
2023-02-05 23:14:10 +01:00
```
2023-11-29 13:30:13 +01:00
To get the previous stable version of Smarty, Smarty 4, use:
2023-02-05 23:14:10 +01:00
```shell
2023-11-29 13:30:13 +01:00
composer require smarty/smarty:^4
2023-02-05 23:14:10 +01:00
```
Here's how you create an instance of Smarty in your PHP scripts:
```php
<?php
// Instantiated via composer
require 'vendor/autoload.php';
Smarty5 (#852) * WIP converting code to PSR-4 * More PSR4 rewriting * Removed autoload filters * WIP making compile classes PSR-4 * WIP making compile classes PSR-4 * Replace Smarty:: with symfony/polyfill-mbstring * WIP making compile classes PSR-4 * finished rewriting all compile classes into PSR-4 * Rewrote all Compile and Compiler classes to PSR-4 * WIP rewriting smarty_internal_method_* * Finished moving smarty_internal_method_* * smarty_internal_resource_* to PSR-4 * Refactored all _runtime_* by merging them into the proper classes or by transforming them into Runtime Extensions. * src/Template/* to PSR-4 * src/sysplugins/* to PSR-4 * Entire src dir now PSR-4 compatible * Add makefile, PSR-4 ModifierCompilers * Rewrote all default modifiers and functions from the plugins folder to PSR-4 classes * Rewrote remaining plugins to PSR-4, plugins dir is now gone. * WIP moving Smarty to PSR-4. * fixed pre/post/output filters and removed some old todo-comments * filter tests passing * Fixed TemplateObject test * Fix CustomResourceAmbiguousTest * Fixed CacheResource implementation and tests * Fixed setfilter * Fixed DefaultPluginHandlerTest for function plugins (blocks still break) * move runPluginFromDefaultHandler to new Runtime class * Introduce formatParamsArray method for recurring code fragment * Fix code duplication in block compilers and fix (most) BlockPluginTests. Default plugin handler blocks still need fixing. * minor fixes * Implemented the DefaultHandlerBlockCompiler, made the dependencies of the template compiler into properties, fixed a couple of unit tests * Removed support for PHP include path, and removed the ::loadPlugin method. * Removed now unneeded PHPunit annotations @run(Tests)InSeparateProcess, @preserveGlobalState and @backupStaticAttributes. Made CacheResourceTestCommon abstract to prevent the base class from running tests (and always failing). Unregister a previously registered stream wrapper. Fixes a lot of tests. * Fix scoping / global state problems in tests by using DI in Default Extension. Also removing a bunch of old fashioned phpdoc annotations that are superseded by namespaces. * Make DefaultExtension lazy load again. * Removed deprecated extends_recursion property and fix bug in CodeFrame compiler due to use of clone. * Fixed BC loading of resource pluging from dir and all ResourcePluginTest tests * Removed PHP functions and checks for the already removed php modifiers. Re-implemented functions as regular functions. Probably should compile these directly. * Fixed stream resources * 2 small fixes for unit tests * Fixed modifiercompiler handling multiple/chained modifiers * Rewrote global static global_tpl_vars to getters/setters on Smarty class, fixing several test cases. Added a ::getValue() method to Variable. * Fixed issue related to scoping of left/right delimiter overrides * Added strlen function, fixing some unit tests * Fix bug in calling BC function handlers. * WIP replacing direct access tpl_vars with proper getter/setters. * WIP * WIP rewriting variable scopes * WIP fixing the complicated variables scopes architecture. Right now more tests are failing than before... :( * Fixed minor unit tests * Made variable scoping more sensible * Fix configfile tests * removed phpplugin, removed now unused uncompiled handler and all checks for this, fixed a refactorbug in InheritanceRuntime. Moved getRenderedTemplateCode method to Smarty\Template. Renamed Cache en Compiled base class to GeneratedPhpFile for more clarity and distinction from Resource classes. Inlined Cached::create into its only caller. Some other minor improvements. Removed php7.1 CI tests. * Removed the allowUndefinedVars check from the smarty error handlers, because undefined vars no longer throw an error, unless smarty->error_unassigned is set to true. * Replace direct access to inheritance property on Template object by proper getter. * converted 3 public properties on Template into getters/setters. unified Template creation code. Provided a getter/setter for the has_nocache_code property. Removed the useless DataObject class. Fixed a few tests. Removed the variable-allow-php-templates property from the docs. * Simplified the (no)caching architecture by: - removing support for $cache_attrs for registered plugins, - removing the undocumented {make_nocache} tag and the deprecated {insert} tag and associated code - removing support for a compile_id property on include tags. Fixes a bug in extends: resources by propagating the nocache-hashes between a master template and it's subtemplates in \Smarty\Template::_subTemplateRender. This might need further improvement. * Removed unneeded magic setters/getters/destructors and the like. * Replaced a bunch of direct property access with getters/setters. * Update test runners: no longer support PHP7.1, add PHP8.2 * Fixed scope in variable assignments in included and extended templates, fixed dependencies for testing freshness of caches. Added some unit tests and fixed a class reference to pass some more tests. * Fix searchParents parameter, fixing GetTemplateVarsTest * @var integer > @var int for vsCode * Fix function caching function name * Fixed cacheability of block plugins. * Moved handling of smarty.block.* to special compilers, because they aren't real tags. Organized tag-stack handling in compiler, unified nocache handling in compiler. * Fixed block append/prepend functionality * Fix testRegisterCompilerFunction by parsing argument correctly. * Made exception msgs exactly the same again, fixing some unit tests * Fix default plugin handler * Simply the "isFresh" method by not including the first param anymore. Fix a couple of unit tests by respecting tag_nocache set by nocache vars used in a tag. * Removed the undocumented {block_parent} and {parent} alternatives to {$smarty.block.parent} and {block_child} and {child} alternatives to {$smarty.block.child} * Fix inhertiance implementation for $smarty.block.child * Fixed all inheritance issues * Handle BC registered compilers and missed parameters for openTag and closeTag. * Fix all foreach unit tests * Fixed the {if} failures. * Fix major {include} bug * Fixed bug in {include} variable assignment and removed some unused/unrequired code * Fix function call compilation using {functionname} syntax for in-template defined functions. * Drop a unit tests bc we no longer support direct access to PHP-functinos such as sin() * Fixed all scope assignment bugs * Convert isset and empty to modifiercomilers, and smooth the error handling to fix unit tests. * Fixed getCachedContent * Add TODO list * Run composer install before online test run * Attempt to fix CI * revise CI/CD workflows, bypass packagist for lexer * Update ci.yml * Update ci.yml * fixes in source files * Update ci.yml * Update ci.yml * attempt to load smarty-lexer directly from zip file * Shouldnt need Github token now * correct type of repository * Updated the changelog * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. Deactivated merge_compiled_includes and the {include inline} attribute. They don't seem to do much in terms of performance, but we'll have to check back. * updated todo * Fix smarty-lexer dependency for the time being * Fix smarty-lexer dependency for the time being (remove direct ref to github) * Pushed Lexers/Parsers into VCS again in order to be able to deliver using Packagist/Composer * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. * Run make regardless of timestamps, so we are sure unit tests run with the generated PHP code, not with accidental human made changes to Lexer/Parser. * Update composer packages cache key Update composer packages cache key to trigger refresh on lexer * 4.0.2 of smarty-lexer is released, use that * Throw compile error when using a modifier where it won't work. Fixes #526. * verify that native PHP functions cannot be used as a modifier and verify that an easy userland workaround exists. Fixes #813. * Add test for registering compiler plugin with positional params. Fixes #164 * move test methods because some other test methods rely on their relative positions * Smarty no longer calls `mb_internal_encoding()` and doesn't check for deprecated `mbstring.func_overload` ini directive. Fixes #480. * Generated `<script>` tags lo longer have deprecated `type="text/javascript"` or `language="Javascript"` attributes. Fixes #815. * Fix error in docs on prepend/append. Fixes #818. * Move all creating of templates to Smarty::createTemplate, adding a private property containing previously generated templates for speed. * Load compiled object in template constructor so it will be cached. * WIP for performance improvements. Removed $smarty->_current_file and $smarty->allow_ambiguous_resources properties, both unused. Removed public Source::filepath property. Cached an Compiled files (and Exceptions) no longer rely on the filepath being set. Removed explicit tests for cached and compiled filenames. The exact implementation is not important. Added tests for compile_check property, fixing a file_exists check that would always be done on source template files, even when compile_check was true. Remove code duplication between Source en Config classes. Added a local $_smarty_current_dir to the generated code files for backwards compatability for {$smarty.current_dir}. * remove additional calls to getCached() * updated todo * Add mkdocs for docs * add missing folder for unit tests * Revert latest CI changes, we'll update docs by hand for now * multiversion mkdocs config * fixes to docs * WIP improving the docs * Improved another chunk of the designers docs * Finished improving designers docs * Update code examples to use Smarty\Smarty and autoload instead of require_once calls and new Smarty * Further WIP improving docs * Updated changelog and todo list * WIP on API docs * WIP docs (added page on config) * Fixed markdown syntax. Fixes #879 * Added full support and documentation for ternary operator. Fixes #881 * updated changelog * fixed error in the mkdocs TOC * Added support for null coalescing operator Fixes #882 * Add docs for null coalescing * more docs * Improved docs on compile checking and inheritance * Rewrote docs on filters and resources. * Add makefile entries for generating docs * Docs on caching * finished docs on security and extending smarty * Added Smarty::setExtensions(), fixed unit test for the null coalescing operator. Updated docs about registering a custom extension. * updated todos * fix template invalidation when migrating to 5.0
2023-08-08 00:04:14 +02:00
use Smarty\Smarty;
$smarty = new Smarty();
// or ...
// Instantiated directly
require("/path/to/smarty/libs/Smarty.class.php");
use Smarty\Smarty;
$smarty = new Smarty();
```
2023-02-05 23:14:10 +01:00
Now that the library files are in place, it's time to set up the Smarty
directories for your application.
Smarty5 (#852) * WIP converting code to PSR-4 * More PSR4 rewriting * Removed autoload filters * WIP making compile classes PSR-4 * WIP making compile classes PSR-4 * Replace Smarty:: with symfony/polyfill-mbstring * WIP making compile classes PSR-4 * finished rewriting all compile classes into PSR-4 * Rewrote all Compile and Compiler classes to PSR-4 * WIP rewriting smarty_internal_method_* * Finished moving smarty_internal_method_* * smarty_internal_resource_* to PSR-4 * Refactored all _runtime_* by merging them into the proper classes or by transforming them into Runtime Extensions. * src/Template/* to PSR-4 * src/sysplugins/* to PSR-4 * Entire src dir now PSR-4 compatible * Add makefile, PSR-4 ModifierCompilers * Rewrote all default modifiers and functions from the plugins folder to PSR-4 classes * Rewrote remaining plugins to PSR-4, plugins dir is now gone. * WIP moving Smarty to PSR-4. * fixed pre/post/output filters and removed some old todo-comments * filter tests passing * Fixed TemplateObject test * Fix CustomResourceAmbiguousTest * Fixed CacheResource implementation and tests * Fixed setfilter * Fixed DefaultPluginHandlerTest for function plugins (blocks still break) * move runPluginFromDefaultHandler to new Runtime class * Introduce formatParamsArray method for recurring code fragment * Fix code duplication in block compilers and fix (most) BlockPluginTests. Default plugin handler blocks still need fixing. * minor fixes * Implemented the DefaultHandlerBlockCompiler, made the dependencies of the template compiler into properties, fixed a couple of unit tests * Removed support for PHP include path, and removed the ::loadPlugin method. * Removed now unneeded PHPunit annotations @run(Tests)InSeparateProcess, @preserveGlobalState and @backupStaticAttributes. Made CacheResourceTestCommon abstract to prevent the base class from running tests (and always failing). Unregister a previously registered stream wrapper. Fixes a lot of tests. * Fix scoping / global state problems in tests by using DI in Default Extension. Also removing a bunch of old fashioned phpdoc annotations that are superseded by namespaces. * Make DefaultExtension lazy load again. * Removed deprecated extends_recursion property and fix bug in CodeFrame compiler due to use of clone. * Fixed BC loading of resource pluging from dir and all ResourcePluginTest tests * Removed PHP functions and checks for the already removed php modifiers. Re-implemented functions as regular functions. Probably should compile these directly. * Fixed stream resources * 2 small fixes for unit tests * Fixed modifiercompiler handling multiple/chained modifiers * Rewrote global static global_tpl_vars to getters/setters on Smarty class, fixing several test cases. Added a ::getValue() method to Variable. * Fixed issue related to scoping of left/right delimiter overrides * Added strlen function, fixing some unit tests * Fix bug in calling BC function handlers. * WIP replacing direct access tpl_vars with proper getter/setters. * WIP * WIP rewriting variable scopes * WIP fixing the complicated variables scopes architecture. Right now more tests are failing than before... :( * Fixed minor unit tests * Made variable scoping more sensible * Fix configfile tests * removed phpplugin, removed now unused uncompiled handler and all checks for this, fixed a refactorbug in InheritanceRuntime. Moved getRenderedTemplateCode method to Smarty\Template. Renamed Cache en Compiled base class to GeneratedPhpFile for more clarity and distinction from Resource classes. Inlined Cached::create into its only caller. Some other minor improvements. Removed php7.1 CI tests. * Removed the allowUndefinedVars check from the smarty error handlers, because undefined vars no longer throw an error, unless smarty->error_unassigned is set to true. * Replace direct access to inheritance property on Template object by proper getter. * converted 3 public properties on Template into getters/setters. unified Template creation code. Provided a getter/setter for the has_nocache_code property. Removed the useless DataObject class. Fixed a few tests. Removed the variable-allow-php-templates property from the docs. * Simplified the (no)caching architecture by: - removing support for $cache_attrs for registered plugins, - removing the undocumented {make_nocache} tag and the deprecated {insert} tag and associated code - removing support for a compile_id property on include tags. Fixes a bug in extends: resources by propagating the nocache-hashes between a master template and it's subtemplates in \Smarty\Template::_subTemplateRender. This might need further improvement. * Removed unneeded magic setters/getters/destructors and the like. * Replaced a bunch of direct property access with getters/setters. * Update test runners: no longer support PHP7.1, add PHP8.2 * Fixed scope in variable assignments in included and extended templates, fixed dependencies for testing freshness of caches. Added some unit tests and fixed a class reference to pass some more tests. * Fix searchParents parameter, fixing GetTemplateVarsTest * @var integer > @var int for vsCode * Fix function caching function name * Fixed cacheability of block plugins. * Moved handling of smarty.block.* to special compilers, because they aren't real tags. Organized tag-stack handling in compiler, unified nocache handling in compiler. * Fixed block append/prepend functionality * Fix testRegisterCompilerFunction by parsing argument correctly. * Made exception msgs exactly the same again, fixing some unit tests * Fix default plugin handler * Simply the "isFresh" method by not including the first param anymore. Fix a couple of unit tests by respecting tag_nocache set by nocache vars used in a tag. * Removed the undocumented {block_parent} and {parent} alternatives to {$smarty.block.parent} and {block_child} and {child} alternatives to {$smarty.block.child} * Fix inhertiance implementation for $smarty.block.child * Fixed all inheritance issues * Handle BC registered compilers and missed parameters for openTag and closeTag. * Fix all foreach unit tests * Fixed the {if} failures. * Fix major {include} bug * Fixed bug in {include} variable assignment and removed some unused/unrequired code * Fix function call compilation using {functionname} syntax for in-template defined functions. * Drop a unit tests bc we no longer support direct access to PHP-functinos such as sin() * Fixed all scope assignment bugs * Convert isset and empty to modifiercomilers, and smooth the error handling to fix unit tests. * Fixed getCachedContent * Add TODO list * Run composer install before online test run * Attempt to fix CI * revise CI/CD workflows, bypass packagist for lexer * Update ci.yml * Update ci.yml * fixes in source files * Update ci.yml * Update ci.yml * attempt to load smarty-lexer directly from zip file * Shouldnt need Github token now * correct type of repository * Updated the changelog * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. Deactivated merge_compiled_includes and the {include inline} attribute. They don't seem to do much in terms of performance, but we'll have to check back. * updated todo * Fix smarty-lexer dependency for the time being * Fix smarty-lexer dependency for the time being (remove direct ref to github) * Pushed Lexers/Parsers into VCS again in order to be able to deliver using Packagist/Composer * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. * Run make regardless of timestamps, so we are sure unit tests run with the generated PHP code, not with accidental human made changes to Lexer/Parser. * Update composer packages cache key Update composer packages cache key to trigger refresh on lexer * 4.0.2 of smarty-lexer is released, use that * Throw compile error when using a modifier where it won't work. Fixes #526. * verify that native PHP functions cannot be used as a modifier and verify that an easy userland workaround exists. Fixes #813. * Add test for registering compiler plugin with positional params. Fixes #164 * move test methods because some other test methods rely on their relative positions * Smarty no longer calls `mb_internal_encoding()` and doesn't check for deprecated `mbstring.func_overload` ini directive. Fixes #480. * Generated `<script>` tags lo longer have deprecated `type="text/javascript"` or `language="Javascript"` attributes. Fixes #815. * Fix error in docs on prepend/append. Fixes #818. * Move all creating of templates to Smarty::createTemplate, adding a private property containing previously generated templates for speed. * Load compiled object in template constructor so it will be cached. * WIP for performance improvements. Removed $smarty->_current_file and $smarty->allow_ambiguous_resources properties, both unused. Removed public Source::filepath property. Cached an Compiled files (and Exceptions) no longer rely on the filepath being set. Removed explicit tests for cached and compiled filenames. The exact implementation is not important. Added tests for compile_check property, fixing a file_exists check that would always be done on source template files, even when compile_check was true. Remove code duplication between Source en Config classes. Added a local $_smarty_current_dir to the generated code files for backwards compatability for {$smarty.current_dir}. * remove additional calls to getCached() * updated todo * Add mkdocs for docs * add missing folder for unit tests * Revert latest CI changes, we'll update docs by hand for now * multiversion mkdocs config * fixes to docs * WIP improving the docs * Improved another chunk of the designers docs * Finished improving designers docs * Update code examples to use Smarty\Smarty and autoload instead of require_once calls and new Smarty * Further WIP improving docs * Updated changelog and todo list * WIP on API docs * WIP docs (added page on config) * Fixed markdown syntax. Fixes #879 * Added full support and documentation for ternary operator. Fixes #881 * updated changelog * fixed error in the mkdocs TOC * Added support for null coalescing operator Fixes #882 * Add docs for null coalescing * more docs * Improved docs on compile checking and inheritance * Rewrote docs on filters and resources. * Add makefile entries for generating docs * Docs on caching * finished docs on security and extending smarty * Added Smarty::setExtensions(), fixed unit test for the null coalescing operator. Updated docs about registering a custom extension. * updated todos * fix template invalidation when migrating to 5.0
2023-08-08 00:04:14 +02:00
Smarty requires four directories which are by default named `templates`, `configs`, `templates_c` and `cache`
relative to the current working directory.
The defaults can be changed as follows:
Smarty5 (#852) * WIP converting code to PSR-4 * More PSR4 rewriting * Removed autoload filters * WIP making compile classes PSR-4 * WIP making compile classes PSR-4 * Replace Smarty:: with symfony/polyfill-mbstring * WIP making compile classes PSR-4 * finished rewriting all compile classes into PSR-4 * Rewrote all Compile and Compiler classes to PSR-4 * WIP rewriting smarty_internal_method_* * Finished moving smarty_internal_method_* * smarty_internal_resource_* to PSR-4 * Refactored all _runtime_* by merging them into the proper classes or by transforming them into Runtime Extensions. * src/Template/* to PSR-4 * src/sysplugins/* to PSR-4 * Entire src dir now PSR-4 compatible * Add makefile, PSR-4 ModifierCompilers * Rewrote all default modifiers and functions from the plugins folder to PSR-4 classes * Rewrote remaining plugins to PSR-4, plugins dir is now gone. * WIP moving Smarty to PSR-4. * fixed pre/post/output filters and removed some old todo-comments * filter tests passing * Fixed TemplateObject test * Fix CustomResourceAmbiguousTest * Fixed CacheResource implementation and tests * Fixed setfilter * Fixed DefaultPluginHandlerTest for function plugins (blocks still break) * move runPluginFromDefaultHandler to new Runtime class * Introduce formatParamsArray method for recurring code fragment * Fix code duplication in block compilers and fix (most) BlockPluginTests. Default plugin handler blocks still need fixing. * minor fixes * Implemented the DefaultHandlerBlockCompiler, made the dependencies of the template compiler into properties, fixed a couple of unit tests * Removed support for PHP include path, and removed the ::loadPlugin method. * Removed now unneeded PHPunit annotations @run(Tests)InSeparateProcess, @preserveGlobalState and @backupStaticAttributes. Made CacheResourceTestCommon abstract to prevent the base class from running tests (and always failing). Unregister a previously registered stream wrapper. Fixes a lot of tests. * Fix scoping / global state problems in tests by using DI in Default Extension. Also removing a bunch of old fashioned phpdoc annotations that are superseded by namespaces. * Make DefaultExtension lazy load again. * Removed deprecated extends_recursion property and fix bug in CodeFrame compiler due to use of clone. * Fixed BC loading of resource pluging from dir and all ResourcePluginTest tests * Removed PHP functions and checks for the already removed php modifiers. Re-implemented functions as regular functions. Probably should compile these directly. * Fixed stream resources * 2 small fixes for unit tests * Fixed modifiercompiler handling multiple/chained modifiers * Rewrote global static global_tpl_vars to getters/setters on Smarty class, fixing several test cases. Added a ::getValue() method to Variable. * Fixed issue related to scoping of left/right delimiter overrides * Added strlen function, fixing some unit tests * Fix bug in calling BC function handlers. * WIP replacing direct access tpl_vars with proper getter/setters. * WIP * WIP rewriting variable scopes * WIP fixing the complicated variables scopes architecture. Right now more tests are failing than before... :( * Fixed minor unit tests * Made variable scoping more sensible * Fix configfile tests * removed phpplugin, removed now unused uncompiled handler and all checks for this, fixed a refactorbug in InheritanceRuntime. Moved getRenderedTemplateCode method to Smarty\Template. Renamed Cache en Compiled base class to GeneratedPhpFile for more clarity and distinction from Resource classes. Inlined Cached::create into its only caller. Some other minor improvements. Removed php7.1 CI tests. * Removed the allowUndefinedVars check from the smarty error handlers, because undefined vars no longer throw an error, unless smarty->error_unassigned is set to true. * Replace direct access to inheritance property on Template object by proper getter. * converted 3 public properties on Template into getters/setters. unified Template creation code. Provided a getter/setter for the has_nocache_code property. Removed the useless DataObject class. Fixed a few tests. Removed the variable-allow-php-templates property from the docs. * Simplified the (no)caching architecture by: - removing support for $cache_attrs for registered plugins, - removing the undocumented {make_nocache} tag and the deprecated {insert} tag and associated code - removing support for a compile_id property on include tags. Fixes a bug in extends: resources by propagating the nocache-hashes between a master template and it's subtemplates in \Smarty\Template::_subTemplateRender. This might need further improvement. * Removed unneeded magic setters/getters/destructors and the like. * Replaced a bunch of direct property access with getters/setters. * Update test runners: no longer support PHP7.1, add PHP8.2 * Fixed scope in variable assignments in included and extended templates, fixed dependencies for testing freshness of caches. Added some unit tests and fixed a class reference to pass some more tests. * Fix searchParents parameter, fixing GetTemplateVarsTest * @var integer > @var int for vsCode * Fix function caching function name * Fixed cacheability of block plugins. * Moved handling of smarty.block.* to special compilers, because they aren't real tags. Organized tag-stack handling in compiler, unified nocache handling in compiler. * Fixed block append/prepend functionality * Fix testRegisterCompilerFunction by parsing argument correctly. * Made exception msgs exactly the same again, fixing some unit tests * Fix default plugin handler * Simply the "isFresh" method by not including the first param anymore. Fix a couple of unit tests by respecting tag_nocache set by nocache vars used in a tag. * Removed the undocumented {block_parent} and {parent} alternatives to {$smarty.block.parent} and {block_child} and {child} alternatives to {$smarty.block.child} * Fix inhertiance implementation for $smarty.block.child * Fixed all inheritance issues * Handle BC registered compilers and missed parameters for openTag and closeTag. * Fix all foreach unit tests * Fixed the {if} failures. * Fix major {include} bug * Fixed bug in {include} variable assignment and removed some unused/unrequired code * Fix function call compilation using {functionname} syntax for in-template defined functions. * Drop a unit tests bc we no longer support direct access to PHP-functinos such as sin() * Fixed all scope assignment bugs * Convert isset and empty to modifiercomilers, and smooth the error handling to fix unit tests. * Fixed getCachedContent * Add TODO list * Run composer install before online test run * Attempt to fix CI * revise CI/CD workflows, bypass packagist for lexer * Update ci.yml * Update ci.yml * fixes in source files * Update ci.yml * Update ci.yml * attempt to load smarty-lexer directly from zip file * Shouldnt need Github token now * correct type of repository * Updated the changelog * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. Deactivated merge_compiled_includes and the {include inline} attribute. They don't seem to do much in terms of performance, but we'll have to check back. * updated todo * Fix smarty-lexer dependency for the time being * Fix smarty-lexer dependency for the time being (remove direct ref to github) * Pushed Lexers/Parsers into VCS again in order to be able to deliver using Packagist/Composer * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. * Run make regardless of timestamps, so we are sure unit tests run with the generated PHP code, not with accidental human made changes to Lexer/Parser. * Update composer packages cache key Update composer packages cache key to trigger refresh on lexer * 4.0.2 of smarty-lexer is released, use that * Throw compile error when using a modifier where it won't work. Fixes #526. * verify that native PHP functions cannot be used as a modifier and verify that an easy userland workaround exists. Fixes #813. * Add test for registering compiler plugin with positional params. Fixes #164 * move test methods because some other test methods rely on their relative positions * Smarty no longer calls `mb_internal_encoding()` and doesn't check for deprecated `mbstring.func_overload` ini directive. Fixes #480. * Generated `<script>` tags lo longer have deprecated `type="text/javascript"` or `language="Javascript"` attributes. Fixes #815. * Fix error in docs on prepend/append. Fixes #818. * Move all creating of templates to Smarty::createTemplate, adding a private property containing previously generated templates for speed. * Load compiled object in template constructor so it will be cached. * WIP for performance improvements. Removed $smarty->_current_file and $smarty->allow_ambiguous_resources properties, both unused. Removed public Source::filepath property. Cached an Compiled files (and Exceptions) no longer rely on the filepath being set. Removed explicit tests for cached and compiled filenames. The exact implementation is not important. Added tests for compile_check property, fixing a file_exists check that would always be done on source template files, even when compile_check was true. Remove code duplication between Source en Config classes. Added a local $_smarty_current_dir to the generated code files for backwards compatability for {$smarty.current_dir}. * remove additional calls to getCached() * updated todo * Add mkdocs for docs * add missing folder for unit tests * Revert latest CI changes, we'll update docs by hand for now * multiversion mkdocs config * fixes to docs * WIP improving the docs * Improved another chunk of the designers docs * Finished improving designers docs * Update code examples to use Smarty\Smarty and autoload instead of require_once calls and new Smarty * Further WIP improving docs * Updated changelog and todo list * WIP on API docs * WIP docs (added page on config) * Fixed markdown syntax. Fixes #879 * Added full support and documentation for ternary operator. Fixes #881 * updated changelog * fixed error in the mkdocs TOC * Added support for null coalescing operator Fixes #882 * Add docs for null coalescing * more docs * Improved docs on compile checking and inheritance * Rewrote docs on filters and resources. * Add makefile entries for generating docs * Docs on caching * finished docs on security and extending smarty * Added Smarty::setExtensions(), fixed unit test for the null coalescing operator. Updated docs about registering a custom extension. * updated todos * fix template invalidation when migrating to 5.0
2023-08-08 00:04:14 +02:00
```php
Smarty5 (#852) * WIP converting code to PSR-4 * More PSR4 rewriting * Removed autoload filters * WIP making compile classes PSR-4 * WIP making compile classes PSR-4 * Replace Smarty:: with symfony/polyfill-mbstring * WIP making compile classes PSR-4 * finished rewriting all compile classes into PSR-4 * Rewrote all Compile and Compiler classes to PSR-4 * WIP rewriting smarty_internal_method_* * Finished moving smarty_internal_method_* * smarty_internal_resource_* to PSR-4 * Refactored all _runtime_* by merging them into the proper classes or by transforming them into Runtime Extensions. * src/Template/* to PSR-4 * src/sysplugins/* to PSR-4 * Entire src dir now PSR-4 compatible * Add makefile, PSR-4 ModifierCompilers * Rewrote all default modifiers and functions from the plugins folder to PSR-4 classes * Rewrote remaining plugins to PSR-4, plugins dir is now gone. * WIP moving Smarty to PSR-4. * fixed pre/post/output filters and removed some old todo-comments * filter tests passing * Fixed TemplateObject test * Fix CustomResourceAmbiguousTest * Fixed CacheResource implementation and tests * Fixed setfilter * Fixed DefaultPluginHandlerTest for function plugins (blocks still break) * move runPluginFromDefaultHandler to new Runtime class * Introduce formatParamsArray method for recurring code fragment * Fix code duplication in block compilers and fix (most) BlockPluginTests. Default plugin handler blocks still need fixing. * minor fixes * Implemented the DefaultHandlerBlockCompiler, made the dependencies of the template compiler into properties, fixed a couple of unit tests * Removed support for PHP include path, and removed the ::loadPlugin method. * Removed now unneeded PHPunit annotations @run(Tests)InSeparateProcess, @preserveGlobalState and @backupStaticAttributes. Made CacheResourceTestCommon abstract to prevent the base class from running tests (and always failing). Unregister a previously registered stream wrapper. Fixes a lot of tests. * Fix scoping / global state problems in tests by using DI in Default Extension. Also removing a bunch of old fashioned phpdoc annotations that are superseded by namespaces. * Make DefaultExtension lazy load again. * Removed deprecated extends_recursion property and fix bug in CodeFrame compiler due to use of clone. * Fixed BC loading of resource pluging from dir and all ResourcePluginTest tests * Removed PHP functions and checks for the already removed php modifiers. Re-implemented functions as regular functions. Probably should compile these directly. * Fixed stream resources * 2 small fixes for unit tests * Fixed modifiercompiler handling multiple/chained modifiers * Rewrote global static global_tpl_vars to getters/setters on Smarty class, fixing several test cases. Added a ::getValue() method to Variable. * Fixed issue related to scoping of left/right delimiter overrides * Added strlen function, fixing some unit tests * Fix bug in calling BC function handlers. * WIP replacing direct access tpl_vars with proper getter/setters. * WIP * WIP rewriting variable scopes * WIP fixing the complicated variables scopes architecture. Right now more tests are failing than before... :( * Fixed minor unit tests * Made variable scoping more sensible * Fix configfile tests * removed phpplugin, removed now unused uncompiled handler and all checks for this, fixed a refactorbug in InheritanceRuntime. Moved getRenderedTemplateCode method to Smarty\Template. Renamed Cache en Compiled base class to GeneratedPhpFile for more clarity and distinction from Resource classes. Inlined Cached::create into its only caller. Some other minor improvements. Removed php7.1 CI tests. * Removed the allowUndefinedVars check from the smarty error handlers, because undefined vars no longer throw an error, unless smarty->error_unassigned is set to true. * Replace direct access to inheritance property on Template object by proper getter. * converted 3 public properties on Template into getters/setters. unified Template creation code. Provided a getter/setter for the has_nocache_code property. Removed the useless DataObject class. Fixed a few tests. Removed the variable-allow-php-templates property from the docs. * Simplified the (no)caching architecture by: - removing support for $cache_attrs for registered plugins, - removing the undocumented {make_nocache} tag and the deprecated {insert} tag and associated code - removing support for a compile_id property on include tags. Fixes a bug in extends: resources by propagating the nocache-hashes between a master template and it's subtemplates in \Smarty\Template::_subTemplateRender. This might need further improvement. * Removed unneeded magic setters/getters/destructors and the like. * Replaced a bunch of direct property access with getters/setters. * Update test runners: no longer support PHP7.1, add PHP8.2 * Fixed scope in variable assignments in included and extended templates, fixed dependencies for testing freshness of caches. Added some unit tests and fixed a class reference to pass some more tests. * Fix searchParents parameter, fixing GetTemplateVarsTest * @var integer > @var int for vsCode * Fix function caching function name * Fixed cacheability of block plugins. * Moved handling of smarty.block.* to special compilers, because they aren't real tags. Organized tag-stack handling in compiler, unified nocache handling in compiler. * Fixed block append/prepend functionality * Fix testRegisterCompilerFunction by parsing argument correctly. * Made exception msgs exactly the same again, fixing some unit tests * Fix default plugin handler * Simply the "isFresh" method by not including the first param anymore. Fix a couple of unit tests by respecting tag_nocache set by nocache vars used in a tag. * Removed the undocumented {block_parent} and {parent} alternatives to {$smarty.block.parent} and {block_child} and {child} alternatives to {$smarty.block.child} * Fix inhertiance implementation for $smarty.block.child * Fixed all inheritance issues * Handle BC registered compilers and missed parameters for openTag and closeTag. * Fix all foreach unit tests * Fixed the {if} failures. * Fix major {include} bug * Fixed bug in {include} variable assignment and removed some unused/unrequired code * Fix function call compilation using {functionname} syntax for in-template defined functions. * Drop a unit tests bc we no longer support direct access to PHP-functinos such as sin() * Fixed all scope assignment bugs * Convert isset and empty to modifiercomilers, and smooth the error handling to fix unit tests. * Fixed getCachedContent * Add TODO list * Run composer install before online test run * Attempt to fix CI * revise CI/CD workflows, bypass packagist for lexer * Update ci.yml * Update ci.yml * fixes in source files * Update ci.yml * Update ci.yml * attempt to load smarty-lexer directly from zip file * Shouldnt need Github token now * correct type of repository * Updated the changelog * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. Deactivated merge_compiled_includes and the {include inline} attribute. They don't seem to do much in terms of performance, but we'll have to check back. * updated todo * Fix smarty-lexer dependency for the time being * Fix smarty-lexer dependency for the time being (remove direct ref to github) * Pushed Lexers/Parsers into VCS again in order to be able to deliver using Packagist/Composer * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. * Run make regardless of timestamps, so we are sure unit tests run with the generated PHP code, not with accidental human made changes to Lexer/Parser. * Update composer packages cache key Update composer packages cache key to trigger refresh on lexer * 4.0.2 of smarty-lexer is released, use that * Throw compile error when using a modifier where it won't work. Fixes #526. * verify that native PHP functions cannot be used as a modifier and verify that an easy userland workaround exists. Fixes #813. * Add test for registering compiler plugin with positional params. Fixes #164 * move test methods because some other test methods rely on their relative positions * Smarty no longer calls `mb_internal_encoding()` and doesn't check for deprecated `mbstring.func_overload` ini directive. Fixes #480. * Generated `<script>` tags lo longer have deprecated `type="text/javascript"` or `language="Javascript"` attributes. Fixes #815. * Fix error in docs on prepend/append. Fixes #818. * Move all creating of templates to Smarty::createTemplate, adding a private property containing previously generated templates for speed. * Load compiled object in template constructor so it will be cached. * WIP for performance improvements. Removed $smarty->_current_file and $smarty->allow_ambiguous_resources properties, both unused. Removed public Source::filepath property. Cached an Compiled files (and Exceptions) no longer rely on the filepath being set. Removed explicit tests for cached and compiled filenames. The exact implementation is not important. Added tests for compile_check property, fixing a file_exists check that would always be done on source template files, even when compile_check was true. Remove code duplication between Source en Config classes. Added a local $_smarty_current_dir to the generated code files for backwards compatability for {$smarty.current_dir}. * remove additional calls to getCached() * updated todo * Add mkdocs for docs * add missing folder for unit tests * Revert latest CI changes, we'll update docs by hand for now * multiversion mkdocs config * fixes to docs * WIP improving the docs * Improved another chunk of the designers docs * Finished improving designers docs * Update code examples to use Smarty\Smarty and autoload instead of require_once calls and new Smarty * Further WIP improving docs * Updated changelog and todo list * WIP on API docs * WIP docs (added page on config) * Fixed markdown syntax. Fixes #879 * Added full support and documentation for ternary operator. Fixes #881 * updated changelog * fixed error in the mkdocs TOC * Added support for null coalescing operator Fixes #882 * Add docs for null coalescing * more docs * Improved docs on compile checking and inheritance * Rewrote docs on filters and resources. * Add makefile entries for generating docs * Docs on caching * finished docs on security and extending smarty * Added Smarty::setExtensions(), fixed unit test for the null coalescing operator. Updated docs about registering a custom extension. * updated todos * fix template invalidation when migrating to 5.0
2023-08-08 00:04:14 +02:00
<?php
use Smarty\Smarty;
$smarty = new Smarty();
$smarty->setTemplateDir('/some/template/dir');
$smarty->setConfigDir('/some/config/dir');
$smarty->setCompileDir('/some/compile/dir');
$smarty->setCacheDir('/some/cache/dir');
```
The compile dir and cache dir need to be writable for the user running the PHP script.
> **Note**
>
> This is usually user "nobody" and group "nobody". For OS X users, the
> default is user "www" and group "www". If you are using Apache, you
> can look in your `httpd.conf` file to see what user and group are
> being used.
```bash
chown nobody:nobody /web/www.example.com/guestbook/templates_c/
chmod 770 /web/www.example.com/guestbook/templates_c/
chown nobody:nobody /web/www.example.com/guestbook/cache/
chmod 770 /web/www.example.com/guestbook/cache/
```
You can verify if your system has the correct access rights for
these directories with [`testInstall()`](./programmers/api-functions/api-test-install.md):
```php
Smarty5 (#852) * WIP converting code to PSR-4 * More PSR4 rewriting * Removed autoload filters * WIP making compile classes PSR-4 * WIP making compile classes PSR-4 * Replace Smarty:: with symfony/polyfill-mbstring * WIP making compile classes PSR-4 * finished rewriting all compile classes into PSR-4 * Rewrote all Compile and Compiler classes to PSR-4 * WIP rewriting smarty_internal_method_* * Finished moving smarty_internal_method_* * smarty_internal_resource_* to PSR-4 * Refactored all _runtime_* by merging them into the proper classes or by transforming them into Runtime Extensions. * src/Template/* to PSR-4 * src/sysplugins/* to PSR-4 * Entire src dir now PSR-4 compatible * Add makefile, PSR-4 ModifierCompilers * Rewrote all default modifiers and functions from the plugins folder to PSR-4 classes * Rewrote remaining plugins to PSR-4, plugins dir is now gone. * WIP moving Smarty to PSR-4. * fixed pre/post/output filters and removed some old todo-comments * filter tests passing * Fixed TemplateObject test * Fix CustomResourceAmbiguousTest * Fixed CacheResource implementation and tests * Fixed setfilter * Fixed DefaultPluginHandlerTest for function plugins (blocks still break) * move runPluginFromDefaultHandler to new Runtime class * Introduce formatParamsArray method for recurring code fragment * Fix code duplication in block compilers and fix (most) BlockPluginTests. Default plugin handler blocks still need fixing. * minor fixes * Implemented the DefaultHandlerBlockCompiler, made the dependencies of the template compiler into properties, fixed a couple of unit tests * Removed support for PHP include path, and removed the ::loadPlugin method. * Removed now unneeded PHPunit annotations @run(Tests)InSeparateProcess, @preserveGlobalState and @backupStaticAttributes. Made CacheResourceTestCommon abstract to prevent the base class from running tests (and always failing). Unregister a previously registered stream wrapper. Fixes a lot of tests. * Fix scoping / global state problems in tests by using DI in Default Extension. Also removing a bunch of old fashioned phpdoc annotations that are superseded by namespaces. * Make DefaultExtension lazy load again. * Removed deprecated extends_recursion property and fix bug in CodeFrame compiler due to use of clone. * Fixed BC loading of resource pluging from dir and all ResourcePluginTest tests * Removed PHP functions and checks for the already removed php modifiers. Re-implemented functions as regular functions. Probably should compile these directly. * Fixed stream resources * 2 small fixes for unit tests * Fixed modifiercompiler handling multiple/chained modifiers * Rewrote global static global_tpl_vars to getters/setters on Smarty class, fixing several test cases. Added a ::getValue() method to Variable. * Fixed issue related to scoping of left/right delimiter overrides * Added strlen function, fixing some unit tests * Fix bug in calling BC function handlers. * WIP replacing direct access tpl_vars with proper getter/setters. * WIP * WIP rewriting variable scopes * WIP fixing the complicated variables scopes architecture. Right now more tests are failing than before... :( * Fixed minor unit tests * Made variable scoping more sensible * Fix configfile tests * removed phpplugin, removed now unused uncompiled handler and all checks for this, fixed a refactorbug in InheritanceRuntime. Moved getRenderedTemplateCode method to Smarty\Template. Renamed Cache en Compiled base class to GeneratedPhpFile for more clarity and distinction from Resource classes. Inlined Cached::create into its only caller. Some other minor improvements. Removed php7.1 CI tests. * Removed the allowUndefinedVars check from the smarty error handlers, because undefined vars no longer throw an error, unless smarty->error_unassigned is set to true. * Replace direct access to inheritance property on Template object by proper getter. * converted 3 public properties on Template into getters/setters. unified Template creation code. Provided a getter/setter for the has_nocache_code property. Removed the useless DataObject class. Fixed a few tests. Removed the variable-allow-php-templates property from the docs. * Simplified the (no)caching architecture by: - removing support for $cache_attrs for registered plugins, - removing the undocumented {make_nocache} tag and the deprecated {insert} tag and associated code - removing support for a compile_id property on include tags. Fixes a bug in extends: resources by propagating the nocache-hashes between a master template and it's subtemplates in \Smarty\Template::_subTemplateRender. This might need further improvement. * Removed unneeded magic setters/getters/destructors and the like. * Replaced a bunch of direct property access with getters/setters. * Update test runners: no longer support PHP7.1, add PHP8.2 * Fixed scope in variable assignments in included and extended templates, fixed dependencies for testing freshness of caches. Added some unit tests and fixed a class reference to pass some more tests. * Fix searchParents parameter, fixing GetTemplateVarsTest * @var integer > @var int for vsCode * Fix function caching function name * Fixed cacheability of block plugins. * Moved handling of smarty.block.* to special compilers, because they aren't real tags. Organized tag-stack handling in compiler, unified nocache handling in compiler. * Fixed block append/prepend functionality * Fix testRegisterCompilerFunction by parsing argument correctly. * Made exception msgs exactly the same again, fixing some unit tests * Fix default plugin handler * Simply the "isFresh" method by not including the first param anymore. Fix a couple of unit tests by respecting tag_nocache set by nocache vars used in a tag. * Removed the undocumented {block_parent} and {parent} alternatives to {$smarty.block.parent} and {block_child} and {child} alternatives to {$smarty.block.child} * Fix inhertiance implementation for $smarty.block.child * Fixed all inheritance issues * Handle BC registered compilers and missed parameters for openTag and closeTag. * Fix all foreach unit tests * Fixed the {if} failures. * Fix major {include} bug * Fixed bug in {include} variable assignment and removed some unused/unrequired code * Fix function call compilation using {functionname} syntax for in-template defined functions. * Drop a unit tests bc we no longer support direct access to PHP-functinos such as sin() * Fixed all scope assignment bugs * Convert isset and empty to modifiercomilers, and smooth the error handling to fix unit tests. * Fixed getCachedContent * Add TODO list * Run composer install before online test run * Attempt to fix CI * revise CI/CD workflows, bypass packagist for lexer * Update ci.yml * Update ci.yml * fixes in source files * Update ci.yml * Update ci.yml * attempt to load smarty-lexer directly from zip file * Shouldnt need Github token now * correct type of repository * Updated the changelog * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. Deactivated merge_compiled_includes and the {include inline} attribute. They don't seem to do much in terms of performance, but we'll have to check back. * updated todo * Fix smarty-lexer dependency for the time being * Fix smarty-lexer dependency for the time being (remove direct ref to github) * Pushed Lexers/Parsers into VCS again in order to be able to deliver using Packagist/Composer * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. * Run make regardless of timestamps, so we are sure unit tests run with the generated PHP code, not with accidental human made changes to Lexer/Parser. * Update composer packages cache key Update composer packages cache key to trigger refresh on lexer * 4.0.2 of smarty-lexer is released, use that * Throw compile error when using a modifier where it won't work. Fixes #526. * verify that native PHP functions cannot be used as a modifier and verify that an easy userland workaround exists. Fixes #813. * Add test for registering compiler plugin with positional params. Fixes #164 * move test methods because some other test methods rely on their relative positions * Smarty no longer calls `mb_internal_encoding()` and doesn't check for deprecated `mbstring.func_overload` ini directive. Fixes #480. * Generated `<script>` tags lo longer have deprecated `type="text/javascript"` or `language="Javascript"` attributes. Fixes #815. * Fix error in docs on prepend/append. Fixes #818. * Move all creating of templates to Smarty::createTemplate, adding a private property containing previously generated templates for speed. * Load compiled object in template constructor so it will be cached. * WIP for performance improvements. Removed $smarty->_current_file and $smarty->allow_ambiguous_resources properties, both unused. Removed public Source::filepath property. Cached an Compiled files (and Exceptions) no longer rely on the filepath being set. Removed explicit tests for cached and compiled filenames. The exact implementation is not important. Added tests for compile_check property, fixing a file_exists check that would always be done on source template files, even when compile_check was true. Remove code duplication between Source en Config classes. Added a local $_smarty_current_dir to the generated code files for backwards compatability for {$smarty.current_dir}. * remove additional calls to getCached() * updated todo * Add mkdocs for docs * add missing folder for unit tests * Revert latest CI changes, we'll update docs by hand for now * multiversion mkdocs config * fixes to docs * WIP improving the docs * Improved another chunk of the designers docs * Finished improving designers docs * Update code examples to use Smarty\Smarty and autoload instead of require_once calls and new Smarty * Further WIP improving docs * Updated changelog and todo list * WIP on API docs * WIP docs (added page on config) * Fixed markdown syntax. Fixes #879 * Added full support and documentation for ternary operator. Fixes #881 * updated changelog * fixed error in the mkdocs TOC * Added support for null coalescing operator Fixes #882 * Add docs for null coalescing * more docs * Improved docs on compile checking and inheritance * Rewrote docs on filters and resources. * Add makefile entries for generating docs * Docs on caching * finished docs on security and extending smarty * Added Smarty::setExtensions(), fixed unit test for the null coalescing operator. Updated docs about registering a custom extension. * updated todos * fix template invalidation when migrating to 5.0
2023-08-08 00:04:14 +02:00
<?php
use Smarty\Smarty;
$smarty = new Smarty();
$smarty->setTemplateDir('/some/template/dir');
$smarty->setConfigDir('/some/config/dir');
$smarty->setCompileDir('/some/compile/dir');
$smarty->setCacheDir('/some/cache/dir');
$smarty->testInstall();
```
## Basic usage
Now, let's create the `index.tpl` file that Smarty will display. This
needs to be located in the [`$template_dir`](./programmers/api-variables/variable-template-dir.md).
2023-02-05 23:14:10 +01:00
```smarty
{* Smarty *}
<h1>Hello {$name|escape}, welcome to Smarty!</h1>
```
> **Note**
>
> `{* Smarty *}` is a template [comment](./designers/language-basic-syntax/language-syntax-comments.md). It
> is not required, but it is good practice to start all your template
> files with this comment. It makes the file easy to recognize
> regardless of the file extension. For example, text editors could
> recognize the file and turn on special syntax highlighting.
Now lets edit our php file. We'll create an instance of Smarty,
[`assign()`](./programmers/api-functions/api-assign.md) a template variable and
[`display()`](./programmers/api-functions/api-display.md) the `index.tpl` file.
```php
<?php
require 'vendor/autoload.php';
Smarty5 (#852) * WIP converting code to PSR-4 * More PSR4 rewriting * Removed autoload filters * WIP making compile classes PSR-4 * WIP making compile classes PSR-4 * Replace Smarty:: with symfony/polyfill-mbstring * WIP making compile classes PSR-4 * finished rewriting all compile classes into PSR-4 * Rewrote all Compile and Compiler classes to PSR-4 * WIP rewriting smarty_internal_method_* * Finished moving smarty_internal_method_* * smarty_internal_resource_* to PSR-4 * Refactored all _runtime_* by merging them into the proper classes or by transforming them into Runtime Extensions. * src/Template/* to PSR-4 * src/sysplugins/* to PSR-4 * Entire src dir now PSR-4 compatible * Add makefile, PSR-4 ModifierCompilers * Rewrote all default modifiers and functions from the plugins folder to PSR-4 classes * Rewrote remaining plugins to PSR-4, plugins dir is now gone. * WIP moving Smarty to PSR-4. * fixed pre/post/output filters and removed some old todo-comments * filter tests passing * Fixed TemplateObject test * Fix CustomResourceAmbiguousTest * Fixed CacheResource implementation and tests * Fixed setfilter * Fixed DefaultPluginHandlerTest for function plugins (blocks still break) * move runPluginFromDefaultHandler to new Runtime class * Introduce formatParamsArray method for recurring code fragment * Fix code duplication in block compilers and fix (most) BlockPluginTests. Default plugin handler blocks still need fixing. * minor fixes * Implemented the DefaultHandlerBlockCompiler, made the dependencies of the template compiler into properties, fixed a couple of unit tests * Removed support for PHP include path, and removed the ::loadPlugin method. * Removed now unneeded PHPunit annotations @run(Tests)InSeparateProcess, @preserveGlobalState and @backupStaticAttributes. Made CacheResourceTestCommon abstract to prevent the base class from running tests (and always failing). Unregister a previously registered stream wrapper. Fixes a lot of tests. * Fix scoping / global state problems in tests by using DI in Default Extension. Also removing a bunch of old fashioned phpdoc annotations that are superseded by namespaces. * Make DefaultExtension lazy load again. * Removed deprecated extends_recursion property and fix bug in CodeFrame compiler due to use of clone. * Fixed BC loading of resource pluging from dir and all ResourcePluginTest tests * Removed PHP functions and checks for the already removed php modifiers. Re-implemented functions as regular functions. Probably should compile these directly. * Fixed stream resources * 2 small fixes for unit tests * Fixed modifiercompiler handling multiple/chained modifiers * Rewrote global static global_tpl_vars to getters/setters on Smarty class, fixing several test cases. Added a ::getValue() method to Variable. * Fixed issue related to scoping of left/right delimiter overrides * Added strlen function, fixing some unit tests * Fix bug in calling BC function handlers. * WIP replacing direct access tpl_vars with proper getter/setters. * WIP * WIP rewriting variable scopes * WIP fixing the complicated variables scopes architecture. Right now more tests are failing than before... :( * Fixed minor unit tests * Made variable scoping more sensible * Fix configfile tests * removed phpplugin, removed now unused uncompiled handler and all checks for this, fixed a refactorbug in InheritanceRuntime. Moved getRenderedTemplateCode method to Smarty\Template. Renamed Cache en Compiled base class to GeneratedPhpFile for more clarity and distinction from Resource classes. Inlined Cached::create into its only caller. Some other minor improvements. Removed php7.1 CI tests. * Removed the allowUndefinedVars check from the smarty error handlers, because undefined vars no longer throw an error, unless smarty->error_unassigned is set to true. * Replace direct access to inheritance property on Template object by proper getter. * converted 3 public properties on Template into getters/setters. unified Template creation code. Provided a getter/setter for the has_nocache_code property. Removed the useless DataObject class. Fixed a few tests. Removed the variable-allow-php-templates property from the docs. * Simplified the (no)caching architecture by: - removing support for $cache_attrs for registered plugins, - removing the undocumented {make_nocache} tag and the deprecated {insert} tag and associated code - removing support for a compile_id property on include tags. Fixes a bug in extends: resources by propagating the nocache-hashes between a master template and it's subtemplates in \Smarty\Template::_subTemplateRender. This might need further improvement. * Removed unneeded magic setters/getters/destructors and the like. * Replaced a bunch of direct property access with getters/setters. * Update test runners: no longer support PHP7.1, add PHP8.2 * Fixed scope in variable assignments in included and extended templates, fixed dependencies for testing freshness of caches. Added some unit tests and fixed a class reference to pass some more tests. * Fix searchParents parameter, fixing GetTemplateVarsTest * @var integer > @var int for vsCode * Fix function caching function name * Fixed cacheability of block plugins. * Moved handling of smarty.block.* to special compilers, because they aren't real tags. Organized tag-stack handling in compiler, unified nocache handling in compiler. * Fixed block append/prepend functionality * Fix testRegisterCompilerFunction by parsing argument correctly. * Made exception msgs exactly the same again, fixing some unit tests * Fix default plugin handler * Simply the "isFresh" method by not including the first param anymore. Fix a couple of unit tests by respecting tag_nocache set by nocache vars used in a tag. * Removed the undocumented {block_parent} and {parent} alternatives to {$smarty.block.parent} and {block_child} and {child} alternatives to {$smarty.block.child} * Fix inhertiance implementation for $smarty.block.child * Fixed all inheritance issues * Handle BC registered compilers and missed parameters for openTag and closeTag. * Fix all foreach unit tests * Fixed the {if} failures. * Fix major {include} bug * Fixed bug in {include} variable assignment and removed some unused/unrequired code * Fix function call compilation using {functionname} syntax for in-template defined functions. * Drop a unit tests bc we no longer support direct access to PHP-functinos such as sin() * Fixed all scope assignment bugs * Convert isset and empty to modifiercomilers, and smooth the error handling to fix unit tests. * Fixed getCachedContent * Add TODO list * Run composer install before online test run * Attempt to fix CI * revise CI/CD workflows, bypass packagist for lexer * Update ci.yml * Update ci.yml * fixes in source files * Update ci.yml * Update ci.yml * attempt to load smarty-lexer directly from zip file * Shouldnt need Github token now * correct type of repository * Updated the changelog * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. Deactivated merge_compiled_includes and the {include inline} attribute. They don't seem to do much in terms of performance, but we'll have to check back. * updated todo * Fix smarty-lexer dependency for the time being * Fix smarty-lexer dependency for the time being (remove direct ref to github) * Pushed Lexers/Parsers into VCS again in order to be able to deliver using Packagist/Composer * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. * Run make regardless of timestamps, so we are sure unit tests run with the generated PHP code, not with accidental human made changes to Lexer/Parser. * Update composer packages cache key Update composer packages cache key to trigger refresh on lexer * 4.0.2 of smarty-lexer is released, use that * Throw compile error when using a modifier where it won't work. Fixes #526. * verify that native PHP functions cannot be used as a modifier and verify that an easy userland workaround exists. Fixes #813. * Add test for registering compiler plugin with positional params. Fixes #164 * move test methods because some other test methods rely on their relative positions * Smarty no longer calls `mb_internal_encoding()` and doesn't check for deprecated `mbstring.func_overload` ini directive. Fixes #480. * Generated `<script>` tags lo longer have deprecated `type="text/javascript"` or `language="Javascript"` attributes. Fixes #815. * Fix error in docs on prepend/append. Fixes #818. * Move all creating of templates to Smarty::createTemplate, adding a private property containing previously generated templates for speed. * Load compiled object in template constructor so it will be cached. * WIP for performance improvements. Removed $smarty->_current_file and $smarty->allow_ambiguous_resources properties, both unused. Removed public Source::filepath property. Cached an Compiled files (and Exceptions) no longer rely on the filepath being set. Removed explicit tests for cached and compiled filenames. The exact implementation is not important. Added tests for compile_check property, fixing a file_exists check that would always be done on source template files, even when compile_check was true. Remove code duplication between Source en Config classes. Added a local $_smarty_current_dir to the generated code files for backwards compatability for {$smarty.current_dir}. * remove additional calls to getCached() * updated todo * Add mkdocs for docs * add missing folder for unit tests * Revert latest CI changes, we'll update docs by hand for now * multiversion mkdocs config * fixes to docs * WIP improving the docs * Improved another chunk of the designers docs * Finished improving designers docs * Update code examples to use Smarty\Smarty and autoload instead of require_once calls and new Smarty * Further WIP improving docs * Updated changelog and todo list * WIP on API docs * WIP docs (added page on config) * Fixed markdown syntax. Fixes #879 * Added full support and documentation for ternary operator. Fixes #881 * updated changelog * fixed error in the mkdocs TOC * Added support for null coalescing operator Fixes #882 * Add docs for null coalescing * more docs * Improved docs on compile checking and inheritance * Rewrote docs on filters and resources. * Add makefile entries for generating docs * Docs on caching * finished docs on security and extending smarty * Added Smarty::setExtensions(), fixed unit test for the null coalescing operator. Updated docs about registering a custom extension. * updated todos * fix template invalidation when migrating to 5.0
2023-08-08 00:04:14 +02:00
use Smarty\Smarty;
$smarty = new Smarty();
$smarty->setTemplateDir('/web/www.example.com/guestbook/templates/');
$smarty->setCompileDir('/web/www.example.com/guestbook/templates_c/');
$smarty->setConfigDir('/web/www.example.com/guestbook/configs/');
$smarty->setCacheDir('/web/www.example.com/guestbook/cache/');
$smarty->assign('name', 'Ned');
$smarty->display('index.tpl');
```
> **Note**
>
2023-02-05 23:14:10 +01:00
> In our example, we are setting absolute paths to all the Smarty
> directories. If `/web/www.example.com/guestbook/` is within your PHP
> include\_path, then these settings are not necessary. However, it is
> more efficient and (from experience) less error-prone to set them to
> absolute paths. This ensures that Smarty is getting files from the
> directories you intended.
2023-02-05 23:14:10 +01:00
Now, run your PHP file. You should see *"Hello Ned, welcome to Smarty!"*
You have completed the basic setup for Smarty!
## Escaping
You may have noticed that the example template above renders the `$name` variable using
the [escape modifier](./designers/language-modifiers/language-modifier-escape.md). This
modifier makes string 'safe' to use in the context of an HTML page.
If you are primarily using Smarty for HTML-pages, it is recommended to enable automatic
escaping. This way, you don't have to add `|escape` to every variable you use on a web page.
Smarty will handle it automatically for you!
Enable auto-escaping for HTML as follows:
```php
$smarty->setEscapeHtml(true);
```
2023-02-05 23:14:10 +01:00
## Extended Setup
2023-02-05 23:14:10 +01:00
This is a continuation of the [basic installation](#installation), please read that first!
2023-02-05 23:14:10 +01:00
A slightly more flexible way to set up Smarty is to extend the Smarty
class and initialize your Smarty
environment. So instead of repeatedly setting directory paths, assigning
the same vars, etc., we can do that in one place.
```php
<?php
Smarty5 (#852) * WIP converting code to PSR-4 * More PSR4 rewriting * Removed autoload filters * WIP making compile classes PSR-4 * WIP making compile classes PSR-4 * Replace Smarty:: with symfony/polyfill-mbstring * WIP making compile classes PSR-4 * finished rewriting all compile classes into PSR-4 * Rewrote all Compile and Compiler classes to PSR-4 * WIP rewriting smarty_internal_method_* * Finished moving smarty_internal_method_* * smarty_internal_resource_* to PSR-4 * Refactored all _runtime_* by merging them into the proper classes or by transforming them into Runtime Extensions. * src/Template/* to PSR-4 * src/sysplugins/* to PSR-4 * Entire src dir now PSR-4 compatible * Add makefile, PSR-4 ModifierCompilers * Rewrote all default modifiers and functions from the plugins folder to PSR-4 classes * Rewrote remaining plugins to PSR-4, plugins dir is now gone. * WIP moving Smarty to PSR-4. * fixed pre/post/output filters and removed some old todo-comments * filter tests passing * Fixed TemplateObject test * Fix CustomResourceAmbiguousTest * Fixed CacheResource implementation and tests * Fixed setfilter * Fixed DefaultPluginHandlerTest for function plugins (blocks still break) * move runPluginFromDefaultHandler to new Runtime class * Introduce formatParamsArray method for recurring code fragment * Fix code duplication in block compilers and fix (most) BlockPluginTests. Default plugin handler blocks still need fixing. * minor fixes * Implemented the DefaultHandlerBlockCompiler, made the dependencies of the template compiler into properties, fixed a couple of unit tests * Removed support for PHP include path, and removed the ::loadPlugin method. * Removed now unneeded PHPunit annotations @run(Tests)InSeparateProcess, @preserveGlobalState and @backupStaticAttributes. Made CacheResourceTestCommon abstract to prevent the base class from running tests (and always failing). Unregister a previously registered stream wrapper. Fixes a lot of tests. * Fix scoping / global state problems in tests by using DI in Default Extension. Also removing a bunch of old fashioned phpdoc annotations that are superseded by namespaces. * Make DefaultExtension lazy load again. * Removed deprecated extends_recursion property and fix bug in CodeFrame compiler due to use of clone. * Fixed BC loading of resource pluging from dir and all ResourcePluginTest tests * Removed PHP functions and checks for the already removed php modifiers. Re-implemented functions as regular functions. Probably should compile these directly. * Fixed stream resources * 2 small fixes for unit tests * Fixed modifiercompiler handling multiple/chained modifiers * Rewrote global static global_tpl_vars to getters/setters on Smarty class, fixing several test cases. Added a ::getValue() method to Variable. * Fixed issue related to scoping of left/right delimiter overrides * Added strlen function, fixing some unit tests * Fix bug in calling BC function handlers. * WIP replacing direct access tpl_vars with proper getter/setters. * WIP * WIP rewriting variable scopes * WIP fixing the complicated variables scopes architecture. Right now more tests are failing than before... :( * Fixed minor unit tests * Made variable scoping more sensible * Fix configfile tests * removed phpplugin, removed now unused uncompiled handler and all checks for this, fixed a refactorbug in InheritanceRuntime. Moved getRenderedTemplateCode method to Smarty\Template. Renamed Cache en Compiled base class to GeneratedPhpFile for more clarity and distinction from Resource classes. Inlined Cached::create into its only caller. Some other minor improvements. Removed php7.1 CI tests. * Removed the allowUndefinedVars check from the smarty error handlers, because undefined vars no longer throw an error, unless smarty->error_unassigned is set to true. * Replace direct access to inheritance property on Template object by proper getter. * converted 3 public properties on Template into getters/setters. unified Template creation code. Provided a getter/setter for the has_nocache_code property. Removed the useless DataObject class. Fixed a few tests. Removed the variable-allow-php-templates property from the docs. * Simplified the (no)caching architecture by: - removing support for $cache_attrs for registered plugins, - removing the undocumented {make_nocache} tag and the deprecated {insert} tag and associated code - removing support for a compile_id property on include tags. Fixes a bug in extends: resources by propagating the nocache-hashes between a master template and it's subtemplates in \Smarty\Template::_subTemplateRender. This might need further improvement. * Removed unneeded magic setters/getters/destructors and the like. * Replaced a bunch of direct property access with getters/setters. * Update test runners: no longer support PHP7.1, add PHP8.2 * Fixed scope in variable assignments in included and extended templates, fixed dependencies for testing freshness of caches. Added some unit tests and fixed a class reference to pass some more tests. * Fix searchParents parameter, fixing GetTemplateVarsTest * @var integer > @var int for vsCode * Fix function caching function name * Fixed cacheability of block plugins. * Moved handling of smarty.block.* to special compilers, because they aren't real tags. Organized tag-stack handling in compiler, unified nocache handling in compiler. * Fixed block append/prepend functionality * Fix testRegisterCompilerFunction by parsing argument correctly. * Made exception msgs exactly the same again, fixing some unit tests * Fix default plugin handler * Simply the "isFresh" method by not including the first param anymore. Fix a couple of unit tests by respecting tag_nocache set by nocache vars used in a tag. * Removed the undocumented {block_parent} and {parent} alternatives to {$smarty.block.parent} and {block_child} and {child} alternatives to {$smarty.block.child} * Fix inhertiance implementation for $smarty.block.child * Fixed all inheritance issues * Handle BC registered compilers and missed parameters for openTag and closeTag. * Fix all foreach unit tests * Fixed the {if} failures. * Fix major {include} bug * Fixed bug in {include} variable assignment and removed some unused/unrequired code * Fix function call compilation using {functionname} syntax for in-template defined functions. * Drop a unit tests bc we no longer support direct access to PHP-functinos such as sin() * Fixed all scope assignment bugs * Convert isset and empty to modifiercomilers, and smooth the error handling to fix unit tests. * Fixed getCachedContent * Add TODO list * Run composer install before online test run * Attempt to fix CI * revise CI/CD workflows, bypass packagist for lexer * Update ci.yml * Update ci.yml * fixes in source files * Update ci.yml * Update ci.yml * attempt to load smarty-lexer directly from zip file * Shouldnt need Github token now * correct type of repository * Updated the changelog * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. Deactivated merge_compiled_includes and the {include inline} attribute. They don't seem to do much in terms of performance, but we'll have to check back. * updated todo * Fix smarty-lexer dependency for the time being * Fix smarty-lexer dependency for the time being (remove direct ref to github) * Pushed Lexers/Parsers into VCS again in order to be able to deliver using Packagist/Composer * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. * Run make regardless of timestamps, so we are sure unit tests run with the generated PHP code, not with accidental human made changes to Lexer/Parser. * Update composer packages cache key Update composer packages cache key to trigger refresh on lexer * 4.0.2 of smarty-lexer is released, use that * Throw compile error when using a modifier where it won't work. Fixes #526. * verify that native PHP functions cannot be used as a modifier and verify that an easy userland workaround exists. Fixes #813. * Add test for registering compiler plugin with positional params. Fixes #164 * move test methods because some other test methods rely on their relative positions * Smarty no longer calls `mb_internal_encoding()` and doesn't check for deprecated `mbstring.func_overload` ini directive. Fixes #480. * Generated `<script>` tags lo longer have deprecated `type="text/javascript"` or `language="Javascript"` attributes. Fixes #815. * Fix error in docs on prepend/append. Fixes #818. * Move all creating of templates to Smarty::createTemplate, adding a private property containing previously generated templates for speed. * Load compiled object in template constructor so it will be cached. * WIP for performance improvements. Removed $smarty->_current_file and $smarty->allow_ambiguous_resources properties, both unused. Removed public Source::filepath property. Cached an Compiled files (and Exceptions) no longer rely on the filepath being set. Removed explicit tests for cached and compiled filenames. The exact implementation is not important. Added tests for compile_check property, fixing a file_exists check that would always be done on source template files, even when compile_check was true. Remove code duplication between Source en Config classes. Added a local $_smarty_current_dir to the generated code files for backwards compatability for {$smarty.current_dir}. * remove additional calls to getCached() * updated todo * Add mkdocs for docs * add missing folder for unit tests * Revert latest CI changes, we'll update docs by hand for now * multiversion mkdocs config * fixes to docs * WIP improving the docs * Improved another chunk of the designers docs * Finished improving designers docs * Update code examples to use Smarty\Smarty and autoload instead of require_once calls and new Smarty * Further WIP improving docs * Updated changelog and todo list * WIP on API docs * WIP docs (added page on config) * Fixed markdown syntax. Fixes #879 * Added full support and documentation for ternary operator. Fixes #881 * updated changelog * fixed error in the mkdocs TOC * Added support for null coalescing operator Fixes #882 * Add docs for null coalescing * more docs * Improved docs on compile checking and inheritance * Rewrote docs on filters and resources. * Add makefile entries for generating docs * Docs on caching * finished docs on security and extending smarty * Added Smarty::setExtensions(), fixed unit test for the null coalescing operator. Updated docs about registering a custom extension. * updated todos * fix template invalidation when migrating to 5.0
2023-08-08 00:04:14 +02:00
use Smarty\Smarty;
class My_GuestBook extends Smarty {
public function __construct()
{
parent::__construct();
$this->setTemplateDir('/web/www.example.com/guestbook/templates/');
$this->setCompileDir('/web/www.example.com/guestbook/templates_c/');
$this->setConfigDir('/web/www.example.com/guestbook/configs/');
$this->setCacheDir('/web/www.example.com/guestbook/cache/');
$this->setEscapeHtml(true);
$this->caching = Smarty::CACHING_LIFETIME_CURRENT;
$this->assign('app_name', 'Guest Book');
}
}
```
Smarty5 (#852) * WIP converting code to PSR-4 * More PSR4 rewriting * Removed autoload filters * WIP making compile classes PSR-4 * WIP making compile classes PSR-4 * Replace Smarty:: with symfony/polyfill-mbstring * WIP making compile classes PSR-4 * finished rewriting all compile classes into PSR-4 * Rewrote all Compile and Compiler classes to PSR-4 * WIP rewriting smarty_internal_method_* * Finished moving smarty_internal_method_* * smarty_internal_resource_* to PSR-4 * Refactored all _runtime_* by merging them into the proper classes or by transforming them into Runtime Extensions. * src/Template/* to PSR-4 * src/sysplugins/* to PSR-4 * Entire src dir now PSR-4 compatible * Add makefile, PSR-4 ModifierCompilers * Rewrote all default modifiers and functions from the plugins folder to PSR-4 classes * Rewrote remaining plugins to PSR-4, plugins dir is now gone. * WIP moving Smarty to PSR-4. * fixed pre/post/output filters and removed some old todo-comments * filter tests passing * Fixed TemplateObject test * Fix CustomResourceAmbiguousTest * Fixed CacheResource implementation and tests * Fixed setfilter * Fixed DefaultPluginHandlerTest for function plugins (blocks still break) * move runPluginFromDefaultHandler to new Runtime class * Introduce formatParamsArray method for recurring code fragment * Fix code duplication in block compilers and fix (most) BlockPluginTests. Default plugin handler blocks still need fixing. * minor fixes * Implemented the DefaultHandlerBlockCompiler, made the dependencies of the template compiler into properties, fixed a couple of unit tests * Removed support for PHP include path, and removed the ::loadPlugin method. * Removed now unneeded PHPunit annotations @run(Tests)InSeparateProcess, @preserveGlobalState and @backupStaticAttributes. Made CacheResourceTestCommon abstract to prevent the base class from running tests (and always failing). Unregister a previously registered stream wrapper. Fixes a lot of tests. * Fix scoping / global state problems in tests by using DI in Default Extension. Also removing a bunch of old fashioned phpdoc annotations that are superseded by namespaces. * Make DefaultExtension lazy load again. * Removed deprecated extends_recursion property and fix bug in CodeFrame compiler due to use of clone. * Fixed BC loading of resource pluging from dir and all ResourcePluginTest tests * Removed PHP functions and checks for the already removed php modifiers. Re-implemented functions as regular functions. Probably should compile these directly. * Fixed stream resources * 2 small fixes for unit tests * Fixed modifiercompiler handling multiple/chained modifiers * Rewrote global static global_tpl_vars to getters/setters on Smarty class, fixing several test cases. Added a ::getValue() method to Variable. * Fixed issue related to scoping of left/right delimiter overrides * Added strlen function, fixing some unit tests * Fix bug in calling BC function handlers. * WIP replacing direct access tpl_vars with proper getter/setters. * WIP * WIP rewriting variable scopes * WIP fixing the complicated variables scopes architecture. Right now more tests are failing than before... :( * Fixed minor unit tests * Made variable scoping more sensible * Fix configfile tests * removed phpplugin, removed now unused uncompiled handler and all checks for this, fixed a refactorbug in InheritanceRuntime. Moved getRenderedTemplateCode method to Smarty\Template. Renamed Cache en Compiled base class to GeneratedPhpFile for more clarity and distinction from Resource classes. Inlined Cached::create into its only caller. Some other minor improvements. Removed php7.1 CI tests. * Removed the allowUndefinedVars check from the smarty error handlers, because undefined vars no longer throw an error, unless smarty->error_unassigned is set to true. * Replace direct access to inheritance property on Template object by proper getter. * converted 3 public properties on Template into getters/setters. unified Template creation code. Provided a getter/setter for the has_nocache_code property. Removed the useless DataObject class. Fixed a few tests. Removed the variable-allow-php-templates property from the docs. * Simplified the (no)caching architecture by: - removing support for $cache_attrs for registered plugins, - removing the undocumented {make_nocache} tag and the deprecated {insert} tag and associated code - removing support for a compile_id property on include tags. Fixes a bug in extends: resources by propagating the nocache-hashes between a master template and it's subtemplates in \Smarty\Template::_subTemplateRender. This might need further improvement. * Removed unneeded magic setters/getters/destructors and the like. * Replaced a bunch of direct property access with getters/setters. * Update test runners: no longer support PHP7.1, add PHP8.2 * Fixed scope in variable assignments in included and extended templates, fixed dependencies for testing freshness of caches. Added some unit tests and fixed a class reference to pass some more tests. * Fix searchParents parameter, fixing GetTemplateVarsTest * @var integer > @var int for vsCode * Fix function caching function name * Fixed cacheability of block plugins. * Moved handling of smarty.block.* to special compilers, because they aren't real tags. Organized tag-stack handling in compiler, unified nocache handling in compiler. * Fixed block append/prepend functionality * Fix testRegisterCompilerFunction by parsing argument correctly. * Made exception msgs exactly the same again, fixing some unit tests * Fix default plugin handler * Simply the "isFresh" method by not including the first param anymore. Fix a couple of unit tests by respecting tag_nocache set by nocache vars used in a tag. * Removed the undocumented {block_parent} and {parent} alternatives to {$smarty.block.parent} and {block_child} and {child} alternatives to {$smarty.block.child} * Fix inhertiance implementation for $smarty.block.child * Fixed all inheritance issues * Handle BC registered compilers and missed parameters for openTag and closeTag. * Fix all foreach unit tests * Fixed the {if} failures. * Fix major {include} bug * Fixed bug in {include} variable assignment and removed some unused/unrequired code * Fix function call compilation using {functionname} syntax for in-template defined functions. * Drop a unit tests bc we no longer support direct access to PHP-functinos such as sin() * Fixed all scope assignment bugs * Convert isset and empty to modifiercomilers, and smooth the error handling to fix unit tests. * Fixed getCachedContent * Add TODO list * Run composer install before online test run * Attempt to fix CI * revise CI/CD workflows, bypass packagist for lexer * Update ci.yml * Update ci.yml * fixes in source files * Update ci.yml * Update ci.yml * attempt to load smarty-lexer directly from zip file * Shouldnt need Github token now * correct type of repository * Updated the changelog * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. Deactivated merge_compiled_includes and the {include inline} attribute. They don't seem to do much in terms of performance, but we'll have to check back. * updated todo * Fix smarty-lexer dependency for the time being * Fix smarty-lexer dependency for the time being (remove direct ref to github) * Pushed Lexers/Parsers into VCS again in order to be able to deliver using Packagist/Composer * Re-organized rendering (read source / compile / cache) process to avoid circular dependencies. * Run make regardless of timestamps, so we are sure unit tests run with the generated PHP code, not with accidental human made changes to Lexer/Parser. * Update composer packages cache key Update composer packages cache key to trigger refresh on lexer * 4.0.2 of smarty-lexer is released, use that * Throw compile error when using a modifier where it won't work. Fixes #526. * verify that native PHP functions cannot be used as a modifier and verify that an easy userland workaround exists. Fixes #813. * Add test for registering compiler plugin with positional params. Fixes #164 * move test methods because some other test methods rely on their relative positions * Smarty no longer calls `mb_internal_encoding()` and doesn't check for deprecated `mbstring.func_overload` ini directive. Fixes #480. * Generated `<script>` tags lo longer have deprecated `type="text/javascript"` or `language="Javascript"` attributes. Fixes #815. * Fix error in docs on prepend/append. Fixes #818. * Move all creating of templates to Smarty::createTemplate, adding a private property containing previously generated templates for speed. * Load compiled object in template constructor so it will be cached. * WIP for performance improvements. Removed $smarty->_current_file and $smarty->allow_ambiguous_resources properties, both unused. Removed public Source::filepath property. Cached an Compiled files (and Exceptions) no longer rely on the filepath being set. Removed explicit tests for cached and compiled filenames. The exact implementation is not important. Added tests for compile_check property, fixing a file_exists check that would always be done on source template files, even when compile_check was true. Remove code duplication between Source en Config classes. Added a local $_smarty_current_dir to the generated code files for backwards compatability for {$smarty.current_dir}. * remove additional calls to getCached() * updated todo * Add mkdocs for docs * add missing folder for unit tests * Revert latest CI changes, we'll update docs by hand for now * multiversion mkdocs config * fixes to docs * WIP improving the docs * Improved another chunk of the designers docs * Finished improving designers docs * Update code examples to use Smarty\Smarty and autoload instead of require_once calls and new Smarty * Further WIP improving docs * Updated changelog and todo list * WIP on API docs * WIP docs (added page on config) * Fixed markdown syntax. Fixes #879 * Added full support and documentation for ternary operator. Fixes #881 * updated changelog * fixed error in the mkdocs TOC * Added support for null coalescing operator Fixes #882 * Add docs for null coalescing * more docs * Improved docs on compile checking and inheritance * Rewrote docs on filters and resources. * Add makefile entries for generating docs * Docs on caching * finished docs on security and extending smarty * Added Smarty::setExtensions(), fixed unit test for the null coalescing operator. Updated docs about registering a custom extension. * updated todos * fix template invalidation when migrating to 5.0
2023-08-08 00:04:14 +02:00
Now, we can use `My_GuestBook` instead of `Smarty` in our scripts:
```php
2023-02-05 23:14:10 +01:00
<?php
$smarty = new My_GuestBook();
2023-02-05 23:14:10 +01:00
$smarty->assign('name', 'Ned');
$smarty->display('index.tpl');
```