|
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 |
Jerc Smarty Rookie
Joined: 26 Jan 2010 Posts: 30 Location: Slovenia / Ljubljana
|
Posted: Fri Oct 23, 2015 7:59 am Post subject: using registerClass with function throws Smarty Compiler err |
|
|
I'm not sure if this is a "Smarty Compiler: Syntax error in template" or i don't know how to var_dump a DateTime object.
Case 1 (working: entire array and item on position 0 is printed)
.php
Code: | $smarty->assign('datetime', array(new \DateTime(), new \DateTime())); |
.tpl
Code: | {$datetime|var_dump}<br />
{$datetime[0]|var_dump} |
Case 2 (throwing Smarty Compiler error; entire array is printed, but item on position 0 throws compiler exception):
myclass.php
Code: | namespace Test;
class MyDateTime {
protected static $DATE = array();
public static function init () {
self::$DATE = array(
new \DateTime(),
new \DateTime()
);
}
public static function getValue($constant)
{
return static::$DATE;
}
} |
.php
Code: |
MyDateTime::init();
$smarty->registerClass('Test', 'Test\MyDateTime');
// test output
var_dump(MyDateTime::getValue('DATE')[0]); |
.tpl
Code: | {Test::getValue('DATE')|var_dump}<br />
{Test::getValue('DATE')[0]|var_dump} |
I tried with this combinations and i always got the Smarty compiler exception:
Code: | {(Test::getValue('DATE')[0])|var_dump}
{((Test::getValue('DATE'))[0])|var_dump} |
Updated:
I tried this on Smarty version 3.1.27. |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Fri Oct 23, 2015 5:04 pm Post subject: |
|
|
\Test |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Sat Oct 24, 2015 9:24 pm Post subject: |
|
|
Note: The Smarty template syntax is similar to but not identical with PHP.
Array index after function result is not supported. |
|
Back to top |
|
Jerc Smarty Rookie
Joined: 26 Jan 2010 Posts: 30 Location: Slovenia / Ljubljana
|
Posted: Mon Oct 26, 2015 7:01 am Post subject: |
|
|
Thanks for the reply.
I'll assign variables in tpl or php and use them. |
|
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
|