smarty-php / smarty

Smarty is a template engine for PHP, facilitating the separation of presentation (HTML/CSS) from application logic.
Other
2.22k stars 701 forks source link

Error: For loop not working when using extends resource type #1036

Open Synaptic14 opened 3 weeks ago

Synaptic14 commented 3 weeks ago

When extending a template using the extends resource type, for loops throw "Error: Attempt to assign property "step" on null"

PHP Version: 8.3.6 Smarty Version: 5.3.1

index.php

require_once('vendor/autoload.php');
use Smarty\Smarty;

$smarty = new Smarty();
$smarty->setTemplateDir(__DIR__.'/tpl/');
$smarty->setCompileDir(__DIR__.'/tpc/');

try {
    $smarty->display('extends:parent.tpl|child.tpl');
} catch (Exception $e) {
    echo $e->getMessage();
}

parent.tpl

<!doctype html>
<html lang="en">
<head>
    <title>Smarty Error Example</title>
</head>
<body>
    {block name="content"}{/block}
</body>
</html>

child.tpl

{block name="content"}
    <h1>For Loop</h1>
    <ul>
        {for $i=1 to 10}
            <li>{$i}</li>
        {/for}
    </ul>
{/block}