diff --git a/CHANGELOG.md b/CHANGELOG.md index 967989b1c..9903d7ec5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - The {debug} tag was broken in v5 [#922](https://github.com/smarty-php/smarty/issues/922) +- Documentation on `{if $x is even by $y}` syntax ## [5.0.0-rc2] - 2023-11-11 diff --git a/docs/designers/language-builtin-functions/language-function-foreach.md b/docs/designers/language-builtin-functions/language-function-foreach.md index a0b7b588f..38d151169 100644 --- a/docs/designers/language-builtin-functions/language-function-foreach.md +++ b/docs/designers/language-builtin-functions/language-function-foreach.md @@ -252,7 +252,7 @@ iteration. ```smarty {foreach $myNames as $name} - {if $name@iteration is even by 3} + {if $name@index is even by 3} {$name} {else} {$name} diff --git a/docs/designers/language-builtin-functions/language-function-section.md b/docs/designers/language-builtin-functions/language-function-section.md index ff57e5606..afa6366cd 100644 --- a/docs/designers/language-builtin-functions/language-function-section.md +++ b/docs/designers/language-builtin-functions/language-function-section.md @@ -478,13 +478,13 @@ header block every five rows. ``` -An example that uses the `iteration` property to alternate a text color every +An example that uses the `index` property to alternate a text color every third row. ```smarty {section name=co loop=$contacts} - {if $smarty.section.co.iteration is even by 3} + {if $smarty.section.co.index is even by 3} {$contacts[co].name} {else} {$contacts[co].name} diff --git a/tests/UnitTests/TemplateSource/TagTests/If/CompileIfTest.php b/tests/UnitTests/TemplateSource/TagTests/If/CompileIfTest.php index 9d4debdea..82ee97182 100644 --- a/tests/UnitTests/TemplateSource/TagTests/If/CompileIfTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/If/CompileIfTest.php @@ -103,7 +103,37 @@ public function dataTestIf() array('{if 6 is not even}yes{else}no{/if}', 'no', 'IsNotEven', $i ++), array('{if 3 is odd}yes{else}no{/if}', 'yes', 'IsOdd', $i ++), array('{if 3 is not odd}yes{else}no{/if}', 'no', 'IsNotOdd', $i ++), - array('{$foo=3}{if 3 is odd by $foo}yes{else}no{/if}', 'yes', 'IsOddByVar', $i ++), + + array('{if 0 is even by 3}yes{else}no{/if}', 'yes', 'IsEvenByTest0', $i ++), + array('{if 1 is even by 3}yes{else}no{/if}', 'yes', 'IsEvenByTest1', $i ++), + array('{if 2 is even by 3}yes{else}no{/if}', 'yes', 'IsEvenByTest2', $i ++), + array('{if 3 is even by 3}yes{else}no{/if}', 'no', 'IsEvenByTest3', $i ++), + array('{if 4 is even by 3}yes{else}no{/if}', 'no', 'IsEvenByTest4', $i ++), + array('{if 5 is even by 3}yes{else}no{/if}', 'no', 'IsEvenByTest5', $i ++), + array('{if 6 is even by 3}yes{else}no{/if}', 'yes', 'IsEvenByTest6', $i ++), + array('{if 7 is even by 3}yes{else}no{/if}', 'yes', 'IsEvenByTest7', $i ++), + + array('{if 0 is odd by 3}yes{else}no{/if}', 'no', 'IsOddByTest0', $i ++), + array('{if 1 is odd by 3}yes{else}no{/if}', 'no', 'IsOddByTest1', $i ++), + array('{if 2 is odd by 3}yes{else}no{/if}', 'no', 'IsOddByTest2', $i ++), + array('{if 3 is odd by 3}yes{else}no{/if}', 'yes', 'IsOddByTest3', $i ++), + array('{if 4 is odd by 3}yes{else}no{/if}', 'yes', 'IsOddByTest4', $i ++), + array('{if 5 is odd by 3}yes{else}no{/if}', 'yes', 'IsOddByTest5', $i ++), + array('{if 6 is odd by 3}yes{else}no{/if}', 'no', 'IsOddByTest6', $i ++), + array('{if 7 is odd by 3}yes{else}no{/if}', 'no', 'IsOddByTest7', $i ++), + + array('{if 2 is even by 3}yes{else}no{/if}', 'yes', 'IsEvenByVal1', $i ++), + array('{if 3 is even by 2}yes{else}no{/if}', 'no', 'IsEvenByVal2', $i ++), + array('{if 4 is even by 3}yes{else}no{/if}', 'no', 'IsEvenByVal3', $i ++), + array('{$foo=3}{if 2 is even by $foo}yes{else}no{/if}', 'yes', 'IsEvenByVar1', $i ++), + array('{$foo=2}{if 3 is even by $foo}yes{else}no{/if}', 'no', 'IsEvenByVar2', $i ++), + array('{$foo=3}{if 4 is even by $foo}yes{else}no{/if}', 'no', 'IsEvenByVar3', $i ++), + array('{if 2 is odd by 3}yes{else}no{/if}', 'no', 'IsOddByVal1', $i ++), + array('{if 3 is odd by 2}yes{else}no{/if}', 'yes', 'IsOddByVal2', $i ++), + array('{if 4 is odd by 3}yes{else}no{/if}', 'yes', 'IsOddByVal3', $i ++), + array('{$foo=3}{if 2 is odd by $foo}yes{else}no{/if}', 'no', 'IsOddByVar1', $i ++), + array('{$foo=2}{if 3 is odd by $foo}yes{else}no{/if}', 'yes', 'IsOddByVar2', $i ++), + array('{$foo=3}{if 4 is odd by $foo}yes{else}no{/if}', 'yes', 'IsOddByVar3', $i ++), array('{$foo=3}{$bar=6}{if $bar is not odd by $foo}yes{else}no{/if}', 'yes', 'IsNotOddByVar', $i ++), array('{$foo=3}{$bar=3}{if 3+$bar is not odd by $foo}yes{else}no{/if}', 'yes', 'ExprIsNotOddByVar', $i ++), array('{$foo=2}{$bar=6}{if (3+$bar) is not odd by ($foo+1)}yes{else}no{/if}', 'no', 'ExprIsNotOddByExpr', $i ++),