mirror of
https://github.com/smarty-php/smarty.git
synced 2026-08-04 20:44:13 +02:00
Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9ee3cce380 | |||
| babec0f29b | |||
| 212bf88eb2 | |||
| 26332c9de4 | |||
| af2e12d58e | |||
| 7a58ca2517 | |||
| 9b9660881d | |||
| 052fee3a30 | |||
| 548a67031d | |||
| af54caa65a | |||
| 6c48c44be5 | |||
| 277dfda102 | |||
| 362104ef9f | |||
| 949f3185c4 | |||
| 8fd949ac5d |
@@ -6,6 +6,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Fixed
|
||||
- Registered output filters wouldn't run [#899](https://github.com/smarty-php/smarty/issues/899)
|
||||
- Use of negative numbers in {math} equations [#895](https://github.com/smarty-php/smarty/issues/895)
|
||||
|
||||
### Removed
|
||||
- Removed `$smarty->registered_filters` array
|
||||
|
||||
## [5.0.0-rc1] - 2023-08-08
|
||||
|
||||
### Added
|
||||
- Added support for PHP8.2
|
||||
- Added a new way to extend Smarty functionality using `Smarty::addExtension()` or `Smarty::setExtensions()`. Please see the docs for more information.
|
||||
|
||||
+119
@@ -0,0 +1,119 @@
|
||||
# Contributing to Smarty
|
||||
|
||||
First off, thanks for taking the time to contribute! ❤️
|
||||
|
||||
> And if you like the project, but just don't have time to contribute, that's fine. There are other easy ways to support the project and show your appreciation, which we would also be very happy about:
|
||||
> - Star the project
|
||||
> - Tell a friend about it
|
||||
> - Refer this project in your project's readme
|
||||
> - Mention the project at local meetups and tell your friends/colleagues
|
||||
|
||||
## I Have a Question
|
||||
|
||||
> If you want to ask a question, we assume that you have read the available [Documentation](https://smarty-php.github.io/smarty).
|
||||
|
||||
Before you ask a question, it is best to search for existing [Issues](https://github.com/smarty-php/smarty/issues) that might help you.
|
||||
In case you have found a suitable issue and still need clarification, you can write your question in this issue.
|
||||
It is also advisable to search the internet for answers first.
|
||||
|
||||
If you then still feel the need to ask a question and need clarification, we recommend the following:
|
||||
|
||||
- [Open an Issue](https://github.com/smarty-php/smarty/issues/new).
|
||||
- Provide as much context as you can about what you're running into.
|
||||
- Provide Smarty and PHP versions
|
||||
|
||||
We will then take care of the issue as soon as possible.
|
||||
|
||||
## I Want To Contribute
|
||||
|
||||
> ### Legal Notice
|
||||
> When contributing to this project, you must agree that you have authored 100% of the content,
|
||||
> that you have the necessary rights to the content and that the content you contribute may be provided under the project license.
|
||||
|
||||
### Reporting Bugs
|
||||
|
||||
#### Before Submitting a Bug Report
|
||||
|
||||
A good bug report shouldn't leave others needing to chase you up for more information. Therefore, we ask you to
|
||||
investigate carefully, collect information and describe the issue in detail in your report. Please complete the
|
||||
following steps in advance to help us fix any potential bug as fast as possible.
|
||||
|
||||
- Make sure that you are using the latest version.
|
||||
- Determine if your bug is really a bug and not an error on your side. (Make sure that you have read the [documentation](https://smarty-php.github.io/smarty). If you are looking for support, you might want to check [this section](#i-have-a-question)).
|
||||
- To see if other users have experienced (and potentially already solved) the same issue you are having, check if there is not already a bug report existing for your bug or error in the [bug tracker](https://github.com/smarty-php/smarty/issues?q=label%3Abug).
|
||||
- Also make sure to search the internet (including Stack Overflow) to see if users outside of the GitHub community have discussed the issue.
|
||||
- Collect information about the bug:
|
||||
- For an Exception: please provide the Stack trace
|
||||
- OS (Windows, Linux, macOS)
|
||||
- PHP version
|
||||
- Smarty version
|
||||
- A minimal snippet of (your) code that triggers the bug
|
||||
- Expected output versus actual output
|
||||
- Can you reliably reproduce the issue? And can you also reproduce it with older versions?
|
||||
|
||||
#### How Do I Submit a Good Bug Report?
|
||||
|
||||
> You must never report security related issues, vulnerabilities or bugs including sensitive information to the issue tracker, or elsewhere in public.
|
||||
> For sensitive bugs, please see [SECURITY.md](SECURITY.md).
|
||||
|
||||
We use GitHub issues to track bugs and errors. If you run into an issue with the project:
|
||||
|
||||
- Open an [Issue](https://github.com/smarty-php/smarty/issues/new). (Since we can't be sure at this point whether it is a bug or not, we ask you not to talk about a bug yet and not to label the issue.)
|
||||
- Explain the behavior you would expect and the actual behavior.
|
||||
- Please provide as much context as possible and describe the *reproduction steps* that someone else can follow to recreate the issue on their own. This usually includes your code. For good bug reports you should isolate the problem and create a reduced test case.
|
||||
- Provide the information you collected in the previous section.
|
||||
|
||||
Once it's filed:
|
||||
|
||||
- The project team will label the issue accordingly.
|
||||
- A team member will try to reproduce the issue with your provided steps. If there are no reproduction steps or no obvious way to reproduce the issue, the team will ask you for those steps and mark the issue as `needs-repro`. Bugs with the `needs-repro` tag will not be addressed until they are reproduced.
|
||||
- If the team is able to reproduce the issue, it will be marked `needs-fix`, as well as possibly other tags (such as `critical`), and the issue will be left to be implemented by someone.
|
||||
|
||||
|
||||
|
||||
### Suggesting Enhancements
|
||||
|
||||
This section guides you through submitting an enhancement suggestion for CONTRIBUTING.md, **including completely new features and minor improvements to existing functionality**. Following these guidelines will help maintainers and the community to understand your suggestion and find related suggestions.
|
||||
|
||||
|
||||
#### Before Submitting an Enhancement
|
||||
|
||||
- Make sure that you are using the latest version.
|
||||
- Read the [documentation](https://smarty-php.github.io/smarty) carefully and find out if the functionality is already covered, maybe by an individual configuration.
|
||||
- Perform a [search](https://github.com/smarty-php/smarty/issues) to see if the enhancement has already been suggested. If it has, add a comment to the existing issue instead of opening a new one.
|
||||
- Find out whether your idea fits with the scope and aims of the project. It's up to you to make a strong case to convince the project's developers of the merits of this feature. Keep in mind that we want features that will be useful to the majority of our users and not just a small subset. If you're just targeting a minority of users, consider writing an add-on/plugin library.
|
||||
|
||||
|
||||
#### How Do I Submit a Good Enhancement Suggestion?
|
||||
|
||||
Enhancement suggestions are tracked as [GitHub issues](https://github.com/smarty-php/smarty/issues).
|
||||
|
||||
- Use a **clear and descriptive title** for the issue to identify the suggestion.
|
||||
- Provide a **step-by-step description of the suggested enhancement** in as many details as possible.
|
||||
- **Describe the current behavior** and **explain which behavior you expected to see instead** and why. At this point you can also tell which alternatives do not work for you.
|
||||
- You may want to **include screenshots and animated GIFs** which help you demonstrate the steps or point out the part which the suggestion is related to. You can use [this tool](https://www.cockos.com/licecap/) to record GIFs on macOS and Windows, and [this tool](https://github.com/colinkeenan/silentcast) or [this tool](https://github.com/GNOME/byzanz) on Linux.
|
||||
- **Explain why this enhancement would be useful** to most CONTRIBUTING.md users. You may also want to point out the other projects that solved it better and which could serve as inspiration.
|
||||
|
||||
|
||||
### Improving The Documentation
|
||||
|
||||
The [docs](docs/index.md) are written in markdown, configured in [mkdocs.yml](mkdocs.yml) and published
|
||||
to [GitHub pages](https://smarty-php.github.io/smarty) using [mkdocs](https://www.mkdocs.org/) and [mike](https://github.com/jimporter/mike).
|
||||
|
||||
To preview the docs while you are writing, run:
|
||||
```bash
|
||||
mkdocs serve
|
||||
```
|
||||
This should launch a local web server and give you a link to open in your browser.
|
||||
|
||||
When you are finished, commit your changes and provide a [Pull Request](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request).
|
||||
|
||||
#### Publishing the docs
|
||||
If you are a maintainer, you can publish the document using [mike](https://github.com/jimporter/mike). Make sure you provide the correct version.
|
||||
|
||||
```bash
|
||||
mike deploy 5.x
|
||||
```
|
||||
|
||||
## Attribution
|
||||
This guide is based on the **contributing.md**. [Make your own](https://contributing.md/)!
|
||||
@@ -3,12 +3,6 @@ all: lexers parsers
|
||||
lexers: src/Lexer/ConfigfileLexer.php src/Lexer/TemplateLexer.php
|
||||
parsers: src/Parser/ConfigfileParser.php src/Parser/TemplateParser.php
|
||||
|
||||
docs:
|
||||
mike deploy 5.0
|
||||
|
||||
test-docs:
|
||||
mkdocs serve
|
||||
|
||||
src/Lexer/ConfigfileLexer.php: src/Lexer/ConfigfileLexer.plex
|
||||
php ./utilities/make-lexer.php src/Lexer/ConfigfileLexer.plex src/Lexer/ConfigfileLexer.php
|
||||
|
||||
|
||||
+3
-3
@@ -2,13 +2,13 @@
|
||||
|
||||
## Supported Versions
|
||||
|
||||
Smarty currently supports the latest minor version of Smarty 3 and Smarty 4.
|
||||
Smarty currently supports the latest minor version of Smarty 4 and Smarty 5.
|
||||
|
||||
| Version | Supported |
|
||||
|---------|--------------------|
|
||||
| 5.0.x | :white_check_mark: |
|
||||
| 4.3.x | :white_check_mark: |
|
||||
| 3.1.x | :white_check_mark: |
|
||||
| < 3.1 | :x: |
|
||||
| < 4.3 | :x: |
|
||||
|
||||
## Reporting a Vulnerability
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ footer.tpl:
|
||||
<small>Copyright {$companyName|escape}</small>
|
||||
```
|
||||
|
||||
Smarty will apply the [escape modifier](../designers/language-modifiers/language-modifier-escape.md)
|
||||
Smarty will apply the [escape modifier](../../designers/language-modifiers/language-modifier-escape.md)
|
||||
to the value assigned to the variable
|
||||
`companyName` and replace `{$companyName|escape}` with the result.
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ Intro = """This is a value that spans more
|
||||
|
||||
```
|
||||
|
||||
Values of [config file variables](./language-variables/language-config-variables.md) can be in
|
||||
Values of [config file variables](../../designers/language-variables/language-config-variables.md) can be in
|
||||
quotes, but not necessary. You can use either single or double quotes.
|
||||
If you have a value that spans more than one line, enclose the entire
|
||||
value with triple quotes \("""\). You can put comments into config
|
||||
@@ -81,9 +81,8 @@ $smarty->setConfigOverwrite(false);
|
||||
When config overwrite is disabled, Smarty will create arrays of config file variables when it encounters
|
||||
multiple entries with the same name.
|
||||
|
||||
See also [`{config_load}`](./language-builtin-functions/language-function-config-load.md),
|
||||
[`$config_overwrite`](../programmers/api-variables/variable-config-overwrite.md),
|
||||
[`$default_config_handler_func`](../programmers/api-variables/variable-default-config-handler-func.md),
|
||||
[`getConfigVars()`](../programmers/api-functions/api-get-config-vars.md),
|
||||
[`clearConfig()`](../programmers/api-functions/api-clear-config.md) and
|
||||
[`configLoad()`](../programmers/api-functions/api-config-load.md)
|
||||
See also [`{config_load}`](../../designers/language-builtin-functions/language-function-config-load.md),
|
||||
[`$default_config_handler_func`](../../programmers/api-variables/variable-default-config-handler-func.md),
|
||||
[`getConfigVars()`](../../programmers/api-functions/api-get-config-vars.md),
|
||||
[`clearConfig()`](../../programmers/api-functions/api-clear-config.md) and
|
||||
[`configLoad()`](../../programmers/api-functions/api-config-load.md)
|
||||
|
||||
@@ -55,7 +55,7 @@ You can restrict the methods and properties that can be accessed by
|
||||
listing them in an array as the third registration parameter.
|
||||
|
||||
By default, parameters passed to objects through the templates are
|
||||
passed the same way [custom functions](../../designers/language-custom-functions/index.md) get
|
||||
passed the same way [custom tags](../../designers/language-custom-functions/index.md) get
|
||||
them. An associative array is passed as the first parameter, and the
|
||||
smarty object as the second. If you want the parameters passed one at a
|
||||
time for each argument like traditional object parameter passing, set
|
||||
|
||||
@@ -14,7 +14,7 @@ A simple Smarty template could look like this:
|
||||
|
||||
All Smarty template tags are enclosed within delimiters. By default
|
||||
these are `{` and `}`, but they can be
|
||||
[changed](../../programmers/api-variables/variable-left-delimiter.md).
|
||||
[changed](../../designers/language-basic-syntax/language-escaping.md).
|
||||
|
||||
For the examples in this manual, we will assume that you are using the
|
||||
default delimiters. In Smarty, all content outside of delimiters is
|
||||
@@ -22,12 +22,12 @@ displayed as static content, or unchanged. When Smarty encounters
|
||||
template tags, it attempts to interpret them, and displays the
|
||||
appropriate output in their place.
|
||||
|
||||
The basis components of the Smarty syntax are:
|
||||
The basic components of the Smarty syntax are:
|
||||
|
||||
- [Comments](language-syntax-comments.md)
|
||||
- [Variables](language-syntax-variables.md)
|
||||
- [Operators](language-syntax-operators.md)
|
||||
- [Functions](language-syntax-functions.md)
|
||||
- [Tags](language-syntax-tags.md)
|
||||
- [Attributes](language-syntax-attributes.md)
|
||||
- [Quotes](language-syntax-quotes.md)
|
||||
- [Escaping](language-escaping.md)
|
||||
|
||||
@@ -45,8 +45,7 @@ variables.
|
||||
Smarty's default delimiters { and } cleanly represent presentational
|
||||
content. However, if another set of delimiters suit your needs better,
|
||||
you can change them with Smarty's
|
||||
[`$left_delimiter`](../../programmers/api-variables/variable-left-delimiter.md) and
|
||||
[`$right_delimiter`](../../programmers/api-variables/variable-right-delimiter.md) values.
|
||||
`setLeftDelimiter()` and `setRightDelimiter()` methods.
|
||||
|
||||
> **Note**
|
||||
>
|
||||
@@ -57,8 +56,8 @@ you can change them with Smarty's
|
||||
```php
|
||||
<?php
|
||||
|
||||
$smarty->left_delimiter = '<!--{';
|
||||
$smarty->right_delimiter = '}-->';
|
||||
$smarty->setLeftDelimiter('<!--{');
|
||||
$smarty->setRightDelimiter('}-->');
|
||||
|
||||
$smarty->assign('foo', 'bar');
|
||||
$smarty->assign('name', 'Albert');
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Attributes
|
||||
|
||||
Most of the [functions](./language-syntax-functions.md) take attributes that
|
||||
Most of the [tags](./language-syntax-tags.md) take attributes that
|
||||
specify or modify their behavior. Attributes to Smarty functions are
|
||||
much like HTML attributes. Static values don't have to be enclosed in
|
||||
quotes, but it is required for literal strings. Variables with or
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# Comments
|
||||
|
||||
Template comments are surrounded by asterisks, and that is surrounded by
|
||||
the [delimiter](../../programmers/api-variables/variable-left-delimiter.md) tags like so:
|
||||
the [delimiter](../../designers/language-basic-syntax/language-escaping.md) tags like so:
|
||||
|
||||
## Examples
|
||||
|
||||
|
||||
+3
-3
@@ -1,4 +1,4 @@
|
||||
# Functions
|
||||
# Tags
|
||||
|
||||
Every Smarty tag either prints a [variable](./language-syntax-variables.md) or
|
||||
invokes some sort of function. These are processed and displayed by
|
||||
@@ -31,8 +31,8 @@ within delimiters like so: `{funcname attr1="val1" attr2="val2"}`.
|
||||
[`{strip}`](../language-builtin-functions/language-function-strip.md). There should be no need to
|
||||
change or modify them.
|
||||
|
||||
- Custom functions are **additional** functions implemented via
|
||||
[plugins](../../programmers/plugins.md). They can be modified to your liking, or you can
|
||||
- Custom tags are **additional** tags implemented via
|
||||
[plugins](../../api/extending/introduction.md). They can be modified to your liking, or you can
|
||||
create new ones. [`{html_options}`](../language-custom-functions/language-function-html-options.md)
|
||||
is an example of a custom function.
|
||||
|
||||
@@ -4,7 +4,7 @@ Smarty comes with several built-in functions. These built-in functions
|
||||
are the integral part of the smarty template engine. They are compiled
|
||||
into corresponding inline PHP code for maximum performance.
|
||||
|
||||
You cannot create your own [custom functions](../language-custom-functions/index.md) with the same name; and you
|
||||
You cannot create your own [custom tags](../language-custom-functions/index.md) with the same name; and you
|
||||
should not need to modify the built-in functions.
|
||||
|
||||
A few of these functions have an `assign` attribute which collects the
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
`{block}` is used to define a named area of template source for template
|
||||
inheritance. For details see section of [Template
|
||||
Inheritance](../../programmers/advanced-features/advanced-features-template-inheritance.md).
|
||||
Inheritance](../../api/inheritance.md).
|
||||
|
||||
The `{block}` template source area of a child template will replace the
|
||||
corresponding areas in the parent template(s).
|
||||
@@ -195,7 +195,7 @@ The result would look like
|
||||
```
|
||||
|
||||
See also [Template
|
||||
Inheritance](../../programmers/advanced-features/advanced-features-template-inheritance.md),
|
||||
Inheritance](../../api/inheritance.md),
|
||||
[`$smarty.block.parent`](../language-variables/language-variables-smarty.md#smartyblockparent-languagevariablessmartyblockparent),
|
||||
[`$smarty.block.child`](../language-variables/language-variables-smarty.md#smartyblockchild-languagevariablessmartyblockchild), and
|
||||
[`{extends}`](./language-function-extends.md)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
`{extends}` tags are used in child templates in template inheritance for
|
||||
extending parent templates. For details see section of [Template
|
||||
Inheritance](../../programmers/advanced-features/advanced-features-template-inheritance.md).
|
||||
Inheritance](../../api/inheritance.md).
|
||||
|
||||
- The `{extends}` tag must be on the first line of the template.
|
||||
|
||||
@@ -10,7 +10,7 @@ Inheritance](../../programmers/advanced-features/advanced-features-template-inhe
|
||||
tag it may contain only `{block}` tags. Any other template content
|
||||
is ignored.
|
||||
|
||||
- Use the syntax for [template resources](../../programmers/resources.md) to extend files
|
||||
- Use the syntax for [template resources](../../api/resources.md) to extend files
|
||||
outside the [`$template_dir`](../../programmers/api-variables/variable-template-dir.md) directory.
|
||||
|
||||
## Attributes
|
||||
@@ -33,5 +33,5 @@ Inheritance](../../programmers/advanced-features/advanced-features-template-inhe
|
||||
{extends 'parent.tpl'} {* short-hand *}
|
||||
```
|
||||
|
||||
See also [Template Inheritance](../../programmers/advanced-features/advanced-features-template-inheritance.md)
|
||||
See also [Template Inheritance](../../api/inheritance.md)
|
||||
and [`{block}`](./language-function-block.md).
|
||||
|
||||
@@ -41,7 +41,7 @@ available within the included template.
|
||||
is useful to return values from the included template to the
|
||||
including template.
|
||||
|
||||
- Use the syntax for [template resources](../../programmers/resources.md) to `{include}`
|
||||
- Use the syntax for [template resources](../../api/resources.md) to `{include}`
|
||||
files outside of the [`$template_dir`](../../programmers/api-variables/variable-template-dir.md)
|
||||
directory.
|
||||
|
||||
@@ -183,5 +183,5 @@ current template.
|
||||
{include file="$style_dir/$module.$view.tpl"}
|
||||
```
|
||||
|
||||
See also [template resources](../../programmers/resources.md) and
|
||||
See also [template resources](../../api/resources.md) and
|
||||
[componentized templates](../../appendixes/tips.md#componentized-templates).
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
template delimiters, by default **{** and **}**. You can also use
|
||||
[`{literal}{/literal}`](./language-function-literal.md) to escape blocks of
|
||||
text eg Javascript or CSS. See also the complementary
|
||||
[`{$smarty.ldelim}`](../../programmers/api-variables/variable-left-delimiter.md).
|
||||
[`{$smarty.ldelim}`](../../designers/language-basic-syntax/language-escaping.md).
|
||||
|
||||
```smarty
|
||||
{* this will print literal delimiters out of the template *}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
`{literal}` tags allow a block of data to be taken literally. This is
|
||||
typically used around Javascript or stylesheet blocks where {curly
|
||||
braces} would interfere with the template
|
||||
[delimiter](../../programmers/api-variables/variable-left-delimiter.md) syntax. Anything within
|
||||
[delimiter](../../designers/language-basic-syntax/language-escaping.md) syntax. Anything within
|
||||
`{literal}{/literal}` tags is not interpreted, but displayed as-is. If
|
||||
you need template tags embedded in a `{literal}` block, consider using
|
||||
[`{ldelim}{rdelim}`](./language-function-ldelim.md) to escape the individual
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# Custom Functions
|
||||
# Custom Tags
|
||||
|
||||
Smarty comes with several custom plugin functions that you can use in
|
||||
the templates.
|
||||
|
||||
@@ -22,7 +22,7 @@ output to the template.
|
||||
> templates.
|
||||
>
|
||||
> - Evaluated variables are compiled on every invocation, the compiled
|
||||
> versions are not saved! However, if you have [caching](../../programmers/caching.md)
|
||||
> versions are not saved! However, if you have [caching](../../api/caching/basics.md)
|
||||
> enabled, the output will be cached with the rest of the template.
|
||||
>
|
||||
> - If the content to evaluate doesn't change often, or is used
|
||||
|
||||
@@ -28,7 +28,7 @@ ftp and display the contents.
|
||||
> If security is enabled, and you are fetching a file from the local
|
||||
> file system, `{fetch}` will only allow files from within the
|
||||
> `$secure_dir` path of the security policy. See the
|
||||
> [Security](../../programmers/advanced-features/advanced-features-security.md) section for details.
|
||||
> [Security](../../api/security.md) section for details.
|
||||
|
||||
- If the `assign` attribute is set, the output of the `{fetch}`
|
||||
function will be assigned to this template variable instead of being
|
||||
|
||||
@@ -20,7 +20,7 @@ automatically calculated from the image file if they are not supplied.
|
||||
from. If not given, the web server's document root
|
||||
`$_ENV['DOCUMENT_ROOT']` is used as the base. If security is
|
||||
enabled, then the image must be located in the `$secure_dir` path of
|
||||
the security policy. See the [Security](../../programmers/advanced-features/advanced-features-security.md)
|
||||
the security policy. See the [Security](../../api/security.md)
|
||||
section for details.
|
||||
|
||||
- `href` is the href value to link the image to. If link is supplied,
|
||||
@@ -37,7 +37,7 @@ automatically calculated from the image file if they are not supplied.
|
||||
>
|
||||
> `{html_image}` requires a hit to the disk to read the image and
|
||||
> calculate the height and width. If you don't use template
|
||||
> [caching](../../programmers/caching.md), it is generally better to avoid `{html_image}`
|
||||
> [caching](../../api/caching/basics.md), it is generally better to avoid `{html_image}`
|
||||
> and leave image tags static for optimal performance.
|
||||
|
||||
## Examples
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# {textformat}
|
||||
|
||||
`{textformat}` is a [block function](../../programmers/plugins/plugins-block-functions.md) used to
|
||||
`{textformat}` is a block tag used to
|
||||
format text. It basically cleans up spaces and special characters, and
|
||||
formats paragraphs by wrapping at a boundary and indenting lines.
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# Variable Modifiers
|
||||
|
||||
Variable modifiers can be applied to
|
||||
[variables](../language-variables/index.md), [custom functions](../language-custom-functions/index.md)
|
||||
[variables](../language-variables/index.md), [custom tags](../language-custom-functions/index.md)
|
||||
or strings. To apply a modifier,
|
||||
specify the value followed by a `|` (pipe) and the modifier name. A
|
||||
modifier may accept additional parameters that affect its behavior.
|
||||
@@ -102,4 +102,4 @@ These parameters follow the modifier name and are separated by a `:`
|
||||
|
||||
See also [`registerPlugin()`](../../programmers/api-functions/api-register-plugin.md), [combining
|
||||
modifiers](../language-combining-modifiers.md). and [extending smarty with
|
||||
plugins](../../programmers/plugins.md)
|
||||
plugins](../../api/extending/introduction.md)
|
||||
|
||||
@@ -8,11 +8,11 @@ variable depends on what symbol it is prefixed or enclosed within.
|
||||
- [{$smarty} reserved variable](language-variables-smarty.md)
|
||||
|
||||
Variables in Smarty can be either displayed directly or used as
|
||||
arguments for [functions](../language-basic-syntax/language-syntax-functions.md),
|
||||
arguments for [tags](../language-basic-syntax/language-syntax-tags.md),
|
||||
[attributes](../language-basic-syntax/language-syntax-attributes.md) and
|
||||
[modifiers](../language-modifiers/index.md), inside conditional expressions, etc.
|
||||
To print a variable, simply enclose it in the
|
||||
[delimiters](../../programmers/api-variables/variable-left-delimiter.md) so that it is the only thing
|
||||
[delimiters](../../designers/language-basic-syntax/language-escaping.md) so that it is the only thing
|
||||
contained between them.
|
||||
|
||||
```smarty
|
||||
|
||||
@@ -110,7 +110,7 @@ zaphod@slartibartfast.example.com<br />
|
||||
|
||||
## Objects
|
||||
|
||||
Properties of [objects](../../programmers/advanced-features/advanced-features-objects.md) assigned from PHP
|
||||
Properties of [objects](../../api/variables/objects.md) assigned from PHP
|
||||
can be referenced by specifying the property name after the `->` symbol.
|
||||
|
||||
```smarty
|
||||
|
||||
@@ -138,12 +138,12 @@ Returns the version of Smarty the template was compiled with.
|
||||
## {$smarty.block.child}
|
||||
|
||||
Returns block text from child template. See [Template
|
||||
inheritance](../../programmers/advanced-features/advanced-features-template-inheritance.md).
|
||||
inheritance](../../api/inheritance.md).
|
||||
|
||||
## {$smarty.block.parent}
|
||||
|
||||
Returns block text from parent template. See [Template
|
||||
inheritance](../../programmers/advanced-features/advanced-features-template-inheritance.md)
|
||||
inheritance](../../api/inheritance.md)
|
||||
|
||||
## {$smarty.ldelim}, {$smarty.rdelim}
|
||||
|
||||
|
||||
+16
-17
@@ -1,36 +1,35 @@
|
||||
Features
|
||||
=======
|
||||
# Features
|
||||
|
||||
Some of Smarty's features:
|
||||
|
||||
- It is extremely fast.
|
||||
- It is efficient since the PHP parser does the dirty work.
|
||||
- No template parsing overhead, only compiles once.
|
||||
- It is smart about [recompiling](#variable.compile.check) only the
|
||||
- It is smart about recompiling only the
|
||||
template files that have changed.
|
||||
- You can easily create your own custom
|
||||
[functions](#language.custom.functions) and [variable
|
||||
modifiers](#language.modifiers), so the template language is
|
||||
[tags](api/extending/tags.md) and [modifiers](api/extending/modifiers.md), so the template language is
|
||||
extremely extensible.
|
||||
- Configurable template [{delimiter}](#variable.left.delimiter) tag
|
||||
- Configurable template [{delimiter}](designers/language-basic-syntax/language-escaping.md) tag
|
||||
syntax, so you can use `{$foo}`, `{{$foo}}`, `<!--{$foo}-->`, etc.
|
||||
- The [`{if}..{elseif}..{else}..{/if}`](#language.function.if)
|
||||
- The [`{if}..{elseif}..{else}..{/if}`](designers/language-builtin-functions/language-function-if.md)
|
||||
constructs are passed to the PHP parser, so the `{if...}` expression
|
||||
syntax can be as simple or as complex an evaluation as you like.
|
||||
- Allows unlimited nesting of
|
||||
[`sections`](#language.function.section), `if's` etc.
|
||||
- Built-in [caching](#caching) support
|
||||
- Arbitrary [template](#resources) sources
|
||||
- [Template Inheritance](#advanced.features.template.inheritance) for
|
||||
[`sections`](designers/language-builtin-functions/language-function-section.md), `if's` etc.
|
||||
- Built-in [caching](api/caching/basics.md) support
|
||||
- Arbitrary [template](api/resources.md) sources
|
||||
- [Template Inheritance](api/inheritance.md) for
|
||||
easy management of template content.
|
||||
- [Plugin](#plugins) architecture
|
||||
- [Plugin](api/extending/introduction.md) architecture
|
||||
|
||||
## Separation of presentation from application code
|
||||
- This means templates can certainly contain logic under the condition
|
||||
that it is for presentation only. Things such as
|
||||
[including](./designers/language-builtin-functions/language-function-include.md) other templates,
|
||||
[alternating](./designers/language-custom-functions/language-function-cycle.md) table row colors,
|
||||
[upper-casing](./designers/language-modifiers/language-modifier-upper.md) a variable,
|
||||
[looping](./designers/language-builtin-functions/language-function-foreach.md) over an array of data and
|
||||
[including](designers/language-builtin-functions/language-function-include.md) other templates,
|
||||
[alternating](designers/language-custom-functions/language-function-cycle.md) table row colors,
|
||||
[upper-casing](designers/language-modifiers/language-modifier-upper.md) a variable,
|
||||
[looping](designers/language-builtin-functions/language-function-foreach.md) over an array of data and
|
||||
rendering it are examples of presentation logic.
|
||||
- This does not mean however that Smarty forces a separation of
|
||||
business and presentation logic. Smarty has no knowledge of which is
|
||||
@@ -61,7 +60,7 @@ inheritance, instead of including other templates we maintain our
|
||||
templates as single pages. We can then manipulate blocks of content
|
||||
within by inheriting them. This makes templates intuitive, efficient and
|
||||
easy to manage. See
|
||||
[Template Inheritance](./programmers/advanced-features/advanced-features-template-inheritance.md)
|
||||
[Template Inheritance](api/inheritance.md)
|
||||
for more info.
|
||||
|
||||
## Why not use XML/XSLT syntax?
|
||||
|
||||
@@ -79,6 +79,8 @@ $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).
|
||||
|
||||
@@ -165,7 +167,7 @@ class My_GuestBook extends Smarty {
|
||||
Now, we can use `My_GuestBook` instead of `Smarty` in our scripts:
|
||||
```php
|
||||
<?php
|
||||
$smarty = new Smarty_GuestBook();
|
||||
$smarty = new My_GuestBook();
|
||||
$smarty->assign('name', 'Ned');
|
||||
$smarty->display('index.tpl');
|
||||
```
|
||||
|
||||
+3
-3
@@ -13,13 +13,13 @@ newspaper article.
|
||||
|
||||
- The article `$headline`, `$tagline`, `$author` and `$body` are
|
||||
content elements, they contain no information about how they will be
|
||||
presented. They are [passed](#api.assign) into Smarty by the
|
||||
presented. They are [passed](getting-started.md#basic-usage) into Smarty by the
|
||||
application.
|
||||
|
||||
- Then the template designer edits the templates and uses a
|
||||
combination of HTML tags and [template tags](#language.basic.syntax)
|
||||
combination of HTML tags and [template tags](designers/language-basic-syntax/language-syntax-tags.md)
|
||||
to format the presentation of these
|
||||
[variables](#language.syntax.variables) with elements such as
|
||||
[variables](designers/language-basic-syntax/language-syntax-variables.md) with elements such as
|
||||
tables, div\'s, background colors, font sizes, style sheets, svg
|
||||
etc.
|
||||
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
\$left\_delimiter {#variable.left.delimiter}
|
||||
=================
|
||||
|
||||
This is the left delimiter used by the template language. Default is
|
||||
`{`.
|
||||
|
||||
See also [`$right_delimiter`](#variable.right.delimiter) and [escaping
|
||||
smarty parsing](#language.escaping) .
|
||||
@@ -1,8 +0,0 @@
|
||||
\$right\_delimiter {#variable.right.delimiter}
|
||||
==================
|
||||
|
||||
This is the right delimiter used by the template language. Default is
|
||||
`}`.
|
||||
|
||||
See also [`$left_delimiter`](#variable.left.delimiter) and [escaping
|
||||
smarty parsing](#language.escaping).
|
||||
+4
-4
@@ -1,17 +1,17 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [[ "$1" =~ ^4\.[0-9\.-rc]+$ ]]; then
|
||||
if [[ "$1" =~ ^5\.[0-9\.]+(-rc[0-9]+)?$ ]]; then
|
||||
printf 'Creating release %s\n' "$1"
|
||||
else
|
||||
echo "Invalid version number: $1. This script can only make v4.x.x releases."
|
||||
echo "Invalid version number: $1. This script can only make v5.x.x releases."
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
git checkout -b "release/$1"
|
||||
sed -i "s/## \\[Unreleased\\]/## \\[Unreleased\\]\\n\\n## \\[$1\\] - $(date +%Y-%m-%d)/" CHANGELOG.md
|
||||
sed -i "s/const SMARTY_VERSION = '[^']\+';/const SMARTY_VERSION = '$1';/" libs/Smarty.class.php
|
||||
sed -i "s/const SMARTY_VERSION = '[^']\+';/const SMARTY_VERSION = '$1';/" src/Smarty.php
|
||||
|
||||
git add CHANGELOG.md libs/Smarty.class.php
|
||||
git add CHANGELOG.md src/Smarty.php
|
||||
git commit -m "version bump"
|
||||
|
||||
git checkout master
|
||||
|
||||
+3
-3
@@ -33,7 +33,7 @@ nav:
|
||||
- Comments: 'designers/language-basic-syntax/language-syntax-comments.md'
|
||||
- Variables: 'designers/language-basic-syntax/language-syntax-variables.md'
|
||||
- Operators: 'designers/language-basic-syntax/language-syntax-operators.md'
|
||||
- Functions: 'designers/language-basic-syntax/language-syntax-functions.md'
|
||||
- Tags: 'designers/language-basic-syntax/language-syntax-tags.md'
|
||||
- Attributes: 'designers/language-basic-syntax/language-syntax-attributes.md'
|
||||
- Quotes: 'designers/language-basic-syntax/language-syntax-quotes.md'
|
||||
- 'Escaping Smarty parsing': 'designers/language-basic-syntax/language-escaping.md'
|
||||
@@ -70,7 +70,7 @@ nav:
|
||||
- 'upper': 'designers/language-modifiers/language-modifier-upper.md'
|
||||
- 'wordwrap': 'designers/language-modifiers/language-modifier-wordwrap.md'
|
||||
- 'Combining Modifiers': 'designers/language-combining-modifiers.md'
|
||||
- 'Builtin Functions':
|
||||
- 'Builtin Tags':
|
||||
- 'Introduction': 'designers/language-builtin-functions/index.md'
|
||||
- '{append}': 'designers/language-builtin-functions/language-function-append.md'
|
||||
- '{assign}': 'designers/language-builtin-functions/language-function-assign.md'
|
||||
@@ -93,7 +93,7 @@ nav:
|
||||
- '{setfilter}': 'designers/language-builtin-functions/language-function-setfilter.md'
|
||||
- '{strip}': 'designers/language-builtin-functions/language-function-strip.md'
|
||||
- '{while}': 'designers/language-builtin-functions/language-function-while.md'
|
||||
- 'Custom Functions':
|
||||
- 'Custom Tags':
|
||||
- 'Introduction': 'designers/language-custom-functions/index.md'
|
||||
- '{counter}': 'designers/language-custom-functions/language-function-counter.md'
|
||||
- '{cycle}': 'designers/language-custom-functions/language-function-cycle.md'
|
||||
|
||||
@@ -464,7 +464,7 @@ class Template extends BaseCompiler {
|
||||
public function compileTag($tag, $args, $parameter = []) {
|
||||
$this->prefixCodeStack[] = $this->prefix_code;
|
||||
$this->prefix_code = [];
|
||||
$result = $this->compileTag2(strtolower($tag), $args, $parameter);
|
||||
$result = $this->compileTag2($tag, $args, $parameter);
|
||||
$this->prefix_code = array_merge($this->prefix_code, array_pop($this->prefixCodeStack));
|
||||
return $result;
|
||||
}
|
||||
@@ -591,6 +591,9 @@ class Template extends BaseCompiler {
|
||||
* @return ?\Smarty\Compile\CompilerInterface tag compiler object or null if not found or untrusted by security policy
|
||||
*/
|
||||
public function getTagCompiler($tag): ?\Smarty\Compile\CompilerInterface {
|
||||
$tag = strtolower($tag);
|
||||
|
||||
$tag = strtolower($tag);
|
||||
|
||||
if (isset($this->smarty->security_policy) && !$this->smarty->security_policy->isTrustedTag($tag, $this)) {
|
||||
return null;
|
||||
@@ -1114,7 +1117,7 @@ class Template extends BaseCompiler {
|
||||
}
|
||||
}
|
||||
|
||||
// call to function previousely defined by {function} tag
|
||||
// call to function previously defined by {function} tag
|
||||
if ($this->canCompileTemplateFunctionCall($tag)) {
|
||||
|
||||
if (!empty($parameter['modifierlist'])) {
|
||||
|
||||
@@ -210,7 +210,6 @@ class Debug extends Data
|
||||
$debObj->error_reporting = E_ALL & ~E_NOTICE;
|
||||
$debObj->debug_tpl = $smarty->debug_tpl ?? 'file:' . __DIR__ . '/../debug.tpl';
|
||||
$debObj->registered_resources = array();
|
||||
$debObj->registered_filters = array();
|
||||
$debObj->escape_html = true;
|
||||
$debObj->caching = \Smarty::CACHING_OFF;
|
||||
// prepare information of assigned variables
|
||||
|
||||
@@ -66,7 +66,7 @@ class Math extends Base {
|
||||
$equation = preg_replace('/\s+/', '', $equation);
|
||||
|
||||
// Adapted from https://www.php.net/manual/en/function.eval.php#107377
|
||||
$number = '(?:\d+(?:[,.]\d+)?|pi|π)'; // What is a number
|
||||
$number = '-?(?:\d+(?:[,.]\d+)?|pi|π)'; // What is a number
|
||||
$functionsOrVars = '((?:0x[a-fA-F0-9]+)|([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*))';
|
||||
$operators = '[,+\/*\^%-]'; // Allowed math operators
|
||||
$regexp = '/^((' . $number . '|' . $functionsOrVars . '|(' . $functionsOrVars . '\s*\((?1)*\)|\((?1)*\)))(?:' . $operators . '(?1))?)+$/';
|
||||
|
||||
@@ -261,6 +261,8 @@ class Security {
|
||||
* @return boolean true if tag is trusted
|
||||
*/
|
||||
public function isTrustedTag($tag_name, $compiler) {
|
||||
$tag_name = strtolower($tag_name);
|
||||
|
||||
// check for internal always required tags
|
||||
if (in_array($tag_name, ['assign', 'call'])) {
|
||||
return true;
|
||||
|
||||
+1
-8
@@ -53,7 +53,7 @@ class Smarty extends \Smarty\TemplateBase {
|
||||
/**
|
||||
* smarty version
|
||||
*/
|
||||
const SMARTY_VERSION = '5.0.0';
|
||||
const SMARTY_VERSION = '5.0.0-rc1';
|
||||
|
||||
/**
|
||||
* define caching modes
|
||||
@@ -384,13 +384,6 @@ class Smarty extends \Smarty\TemplateBase {
|
||||
*/
|
||||
public $registered_classes = [];
|
||||
|
||||
/**
|
||||
* registered filters
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $registered_filters = [];
|
||||
|
||||
/**
|
||||
* registered resources
|
||||
*
|
||||
|
||||
+1
-1
@@ -196,7 +196,7 @@ class Template extends TemplateBase {
|
||||
);
|
||||
} else {
|
||||
if ((!$this->caching || $this->getCached()->getNocacheCode() || $this->getSource()->handler->recompiled)
|
||||
&& !$no_output_filter && isset($this->smarty->registered_filters['output'])
|
||||
&& !$no_output_filter
|
||||
) {
|
||||
echo $this->smarty->runOutputFilters(ob_get_clean(), $this);
|
||||
} else {
|
||||
|
||||
@@ -39,6 +39,17 @@ class RegisterFunctionTest extends PHPUnit_Smarty
|
||||
$this->assertEquals('hello world 1', $this->smarty->fetch('eval:{testfunction value=1}'));
|
||||
}
|
||||
|
||||
/**
|
||||
* test registerPlugin method for function case-sensitive
|
||||
*/
|
||||
public function testRegisterFunctionCaseInsensitive()
|
||||
{
|
||||
$this->smarty->registerPlugin(Smarty::PLUGIN_FUNCTION, 'testFunction', 'myfunction');
|
||||
$this->assertEquals('myfunction',
|
||||
$this->smarty->getRegisteredPlugin(Smarty::PLUGIN_FUNCTION, 'testFunction')[0]);
|
||||
$this->assertEquals('hello world 1', $this->smarty->fetch('eval:{testFunction value=1}'));
|
||||
}
|
||||
|
||||
/**
|
||||
* test registerPlugin method for function class
|
||||
*/
|
||||
@@ -143,7 +154,7 @@ class RegisterFunctionTest extends PHPUnit_Smarty
|
||||
public function testUnregisterFunctionNotRegistered()
|
||||
{
|
||||
$this->smarty->unregisterPlugin(Smarty::PLUGIN_FUNCTION, 'testfunction');
|
||||
$this->assertNull($this->smarty->getRegisteredPlugin(Smarty::PLUGIN_FUNCTION, 'testfunction'));
|
||||
$this->assertNull($this->smarty->getRegisteredPlugin(Smarty::PLUGIN_FUNCTION, 'testfunction'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -153,8 +164,34 @@ class RegisterFunctionTest extends PHPUnit_Smarty
|
||||
{
|
||||
$this->smarty->registerPlugin(Smarty::PLUGIN_BLOCK, 'testfunction', 'myfunction');
|
||||
$this->smarty->unregisterPlugin(Smarty::PLUGIN_FUNCTION, 'testfunction');
|
||||
$this->assertIsArray($this->smarty->getRegisteredPlugin(Smarty::PLUGIN_BLOCK, 'testfunction'));
|
||||
$this->assertIsArray($this->smarty->getRegisteredPlugin(Smarty::PLUGIN_BLOCK, 'testfunction'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test case (in)sensitivy of plugin functions
|
||||
* @param $registerName
|
||||
* @param $templateString
|
||||
* @return void
|
||||
* @throws \Smarty\Exception
|
||||
* @group issue907
|
||||
* @dataProvider dataProviderForCaseSensitivity
|
||||
*/
|
||||
public function testCaseSensitivity($registerName, $templateString) {
|
||||
$this->smarty->registerPlugin(
|
||||
Smarty::PLUGIN_FUNCTION,
|
||||
$registerName,
|
||||
function($params, $smarty) { return 'function-output'; });
|
||||
$this->assertEquals('function-output', $this->smarty->fetch('string:' . $templateString));
|
||||
}
|
||||
|
||||
public function dataProviderForCaseSensitivity() {
|
||||
return [
|
||||
['customTag', '{customTag}'],
|
||||
['customtag', '{customtag}'],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function myfunction($params, $smarty)
|
||||
|
||||
@@ -93,6 +93,14 @@ class MathTest extends PHPUnit_Smarty
|
||||
$this->assertEquals($expected, $this->smarty->fetch($tpl));
|
||||
}
|
||||
|
||||
public function testNegativeNumbers()
|
||||
{
|
||||
$this->smarty->disableSecurity();
|
||||
$expected = "-19 -- 4.1";
|
||||
$tpl = $this->smarty->createTemplate('eval:{$x = 4}{$y = 5.5}{math equation="-2.0*(x+y)" x=$x y=$y} -- {math equation="-20.5 / -5"}');
|
||||
$this->assertEquals($expected, $this->smarty->fetch($tpl));
|
||||
}
|
||||
|
||||
public function testSyntaxFormat()
|
||||
{
|
||||
$this->smarty->disableSecurity();
|
||||
|
||||
Reference in New Issue
Block a user