|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
qUJy5Xg0ve7k Smarty Rookie
Joined: 15 Aug 2018 Posts: 15
|
Posted: Fri Aug 17, 2018 10:03 pm Post subject: Yet another problem, this time with an infinite loop. |
|
|
So I guess I can't update to 3.1.32 (https://www.smarty.net/forums/viewtopic.php?p=93618) and now it looks like I can't update to 3.1.27 either. Somehow the function $smarty->display appears to have changed such that it previously was possible to return a string.
Anyway, I changed it to $smarty->fetch, but somehow it's causing an infinite loop and I simply cannot track it down.
Here's what I'm doing:
I have some text like
Code: | This is {$var} here
|
I get that text from a file, then I try to do
Code: | $parsed = $smarty->fetch($thatText);
|
But it's an infinite loop!
The simple case I found on the internet works:
Code: | <?php
require_once 'smarty\Smarty.class.php';
$smarty = new Smarty();
$smarty->assign('foo','value');
$template_string = 'display {$foo} here';
$ret=$smarty->fetch('string:'.$template_string);
print($ret);
?>
|
But my more complicated example that makes use of
Code: | $smarty->registerPlugin('function', 'getString', 'getLocalizedStringSmarty');
|
causes an infinite loop. I've spent the whole day on it. I can't figure it out.
When I print out the stack trace, I get stumped by some nonsense like this:
Code: | [file] => C:\Program Files (x86)\Bit9\Parity Console\WebUI\smarty\sysplugins\smarty_internal_template.php
[line] => 371
[function] => content_5b774379bd7116_14059517 |
I feel like maybe it's trying to render the entire template infinitely instead of just the string I'm passing? I don't know. Any ideas are welcome. |
|
Back to top |
|
qUJy5Xg0ve7k Smarty Rookie
Joined: 15 Aug 2018 Posts: 15
|
Posted: Fri Aug 17, 2018 10:18 pm Post subject: |
|
|
Okay I've come up with some simple code to display the issue:
test.php:
Code: | <?php
require_once 'smarty/Smarty.class.php';
$smarty = new Smarty();
$smarty->addTemplateDir('../Smarty');
$smarty->assign('animal', 'falcon');
$smarty->registerPlugin('function', 'getString', 'getLocalizedStringSmarty');
function getLocalizedStringSmarty($params, &$smarty){
return $smarty->display('string:I am a {$animal}');
}
$smarty->display('./test.tmpl');
?> |
test.tmpl:
Code: | <?xml version="1.0" encoding="utf-8"?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test Page</title>
</head>
<body>
Hello {getString id='foobar'}
</body>
</html>
|
In 3.1.11 the result is:
Code: | Hello I am a falcon |
In 3.1.27 the result is an infinite loop. Changing display to fetch makes no difference. |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Sat Aug 18, 2018 8:36 am Post subject: |
|
|
That can't be true.
dispay() displays the output directly.
You want fetch().
And you should not use byref, either. |
|
Back to top |
|
qUJy5Xg0ve7k Smarty Rookie
Joined: 15 Aug 2018 Posts: 15
|
Posted: Sat Aug 18, 2018 4:46 pm Post subject: |
|
|
So you're saying I'm lying? Well that's a bizarre response. The code is all right there, you can test it for yourself. It works in 3.1.11, infinite loop in 3.1.27. Changing it to fetch is still an infinite loop.
Last edited by qUJy5Xg0ve7k on Sat Aug 18, 2018 5:20 pm; edited 1 time in total |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Sat Aug 18, 2018 4:55 pm Post subject: |
|
|
Code: | <?php
require_once 'smarty-config.php';
$smarty->assign('animal', 'falcon');
$smarty->registerPlugin('function', 'getString', 'getLocalizedStringSmarty');
function getLocalizedStringSmarty($params, $smarty)
{
return $smarty->fetch('string:I am a {$animal}');
}
$smarty->display(__FILE__);
__halt_compiler()
?><?xml version="1.0" encoding="utf-8"?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test Page</title>
</head>
<body>
Hello {getString id='foobar'}
Smarty: {$smarty.version|escape}
</body>
</html> |
Code: | <?xml version="1.0" encoding="utf-8"?><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test Page</title>
</head>
<body>
Hello I am a falcon
Smarty: 3.1.33-dev-5
</body>
</html> |
|
|
Back to top |
|
qUJy5Xg0ve7k Smarty Rookie
Joined: 15 Aug 2018 Posts: 15
|
Posted: Sat Aug 18, 2018 5:30 pm Post subject: |
|
|
Okay so it seems like it was a bug in 3.1.27 and it is fixed by 3.1.32. But I can't upgrade to that one because of the other bug, which still exists in 3.1.33, (https://www.smarty.net/forums/viewtopic.php?p=93618) so I need a workaround for 3.1.27. Or I guess I can keep going backwards until I find a version with neither bug. |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|