Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

$myObj->$myProp ... how to?

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
fab
Smarty Rookie


Joined: 12 Sep 2003
Posts: 9

PostPosted: Sat Sep 13, 2003 11:56 am    Post subject: $myObj->$myProp ... how to? Reply with quote

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? Rolling Eyes
Back to top
View user's profile Send private message
fab
Smarty Rookie


Joined: 12 Sep 2003
Posts: 9

PostPosted: Sat Sep 13, 2003 1:44 pm    Post subject: Reply with quote

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
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Sat Sep 13, 2003 8:46 pm    Post subject: Reply with quote

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
View user's profile Send private message
fab
Smarty Rookie


Joined: 12 Sep 2003
Posts: 9

PostPosted: Sun Sep 14, 2003 7:46 am    Post subject: Reply with quote

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
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Sun Sep 14, 2003 10:37 pm    Post subject: Reply with quote

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
View user's profile Send private message
fab
Smarty Rookie


Joined: 12 Sep 2003
Posts: 9

PostPosted: Wed Sep 17, 2003 12:48 pm    Post subject: Reply with quote

Sorry i'm late.

Thx you anyway, i'll give it a try.
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP