Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Synaptic14 opened this issue Jun 20, 2024 · 2 comments
Open

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

Synaptic14 opened this issue Jun 20, 2024 · 2 comments

Comments

@Synaptic14
Copy link

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}
@monkeylogic
Copy link

Is there any update on this? We really need a fix.

@antman3351
Copy link

Just open a PR with a fix.
Until then as temporary workaround if you've registered the function range() you can use: {foreach range( 0, $len ) as $i}...{/foreach}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants