Skip to content

Commit

Permalink
fixed ocumentation on {if is even by } syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
wisskid committed Feb 2, 2024
1 parent c0306d9 commit 0912124
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -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

Expand Down
Expand Up @@ -252,7 +252,7 @@ iteration.

```smarty
{foreach $myNames as $name}
{if $name@iteration is even by 3}
{if $name@index is even by 3}
<span style="color: #000">{$name}</span>
{else}
<span style="color: #eee">{$name}</span>
Expand Down
Expand Up @@ -478,13 +478,13 @@ header block every five rows.
</table>
```

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
<table>
{section name=co loop=$contacts}
{if $smarty.section.co.iteration is even by 3}
{if $smarty.section.co.index is even by 3}
<span style="color: #ffffff">{$contacts[co].name}</span>
{else}
<span style="color: #dddddd">{$contacts[co].name}</span>
Expand Down
32 changes: 31 additions & 1 deletion tests/UnitTests/TemplateSource/TagTests/If/CompileIfTest.php
Expand Up @@ -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 ++),
Expand Down

0 comments on commit 0912124

Please sign in to comment.