|
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 |
fab Smarty Rookie
Joined: 12 Sep 2003 Posts: 9
|
Posted: Sat Sep 13, 2003 11:56 am Post subject: $myObj->$myProp ... how to? |
|
|
I have to dynamically call a property for an object, kind of
{$myObj->$myProp}
$myObj and $myProp are both defined and passed to the template.
this example obviously does not work... any suggestion to make it working? |
|
Back to top |
|
fab Smarty Rookie
Joined: 12 Sep 2003 Posts: 9
|
Posted: Sat Sep 13, 2003 1:44 pm Post subject: |
|
|
Hmmmm... Doing on myself.
* quick'n'dirty plugin *
function smarty_function_get_property($params, &$smarty)
{
$obj = $params['object'];
return $obj->$params['property'];
}
* .tpl *
{get_property object="$myObj" property = "$myProp"}
As you can see no parameters check and dirty, but working...
anything better ? C'mon people... |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Sat Sep 13, 2003 8:46 pm Post subject: |
|
|
it occurs to me that I recently saw a post asking the same question where messju answered that the {$obj->$param} notation is broken in 2.5.0. Have you tried the CVS? |
|
Back to top |
|
fab Smarty Rookie
Joined: 12 Sep 2003 Posts: 9
|
Posted: Sun Sep 14, 2003 7:46 am Post subject: |
|
|
2.6.0-RC1 here...
Couldn't get it working right out of the box, only way to get out of trouble was using the "plugin".
Maybe i am missing something?
Thx anyway. |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Sun Sep 14, 2003 10:37 pm Post subject: |
|
|
I can't test 2.6.0-RC1 because it doesn't work at all for me, but I am using a fairly current CVS version and I can verify that {$myObj->$myProp} works there if you want to give it a try. |
|
Back to top |
|
fab Smarty Rookie
Joined: 12 Sep 2003 Posts: 9
|
Posted: Wed Sep 17, 2003 12:48 pm Post subject: |
|
|
Sorry i'm late.
Thx you anyway, i'll give it a try. |
|
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
|