View previous topic :: View next topic |
Author |
Message |
appel Smarty Rookie
Joined: 27 May 2003 Posts: 29
|
Posted: Wed Jul 02, 2003 6:12 pm Post subject: Accessing {$object->array["variable"]} |
|
|
I assigned the object in PHP to this template, but when I try to access an variable in an array in the object I get an error.
Code: |
This is the output: {$PageObject->arrContent.content_text}
|
But I get:
Error message: Smarty: [in pages.tpl line 7]: syntax error: unrecognized tag: $PageObject->arrContent.content_text (Smarty_Compiler.class.php, line 381) |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Wed Jul 02, 2003 6:30 pm Post subject: |
|
|
You may have to do that with an intermediate assignment:
{assign var=temp value=$PageObject->arrContent}
{$temp.content_text}
though I suspect that will introduce a performance issue with PHP causing the array to be copied during the assign to the temp var.
Interesting. I'm not going to bother to try, but does this work?
{$PageObject->arrContent['content_text']} |
|
Back to top |
|
appel Smarty Rookie
Joined: 27 May 2003 Posts: 29
|
Posted: Wed Jul 02, 2003 6:41 pm Post subject: |
|
|
boots wrote: | Interesting. I'm not going to bother to try, but does this work?
{$PageObject->arrContent['content_text']} |
No, that doesn't work either. I tried several ways to do this but I found none that works.
Your assign code works, but as you said it might introduce some perf. issues because to the array copying. |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Thu Jul 03, 2003 8:46 am Post subject: |
|
|
use smarty 2.5.0:
{$PageObject->arrContent.content_text} works as expected for arrays.
{$PageObject->arrContent['content_text']} works as expected for section indices. |
|
Back to top |
|
Ze Smarty Rookie
Joined: 13 Jun 2003 Posts: 5 Location: Rennes, France
|
Posted: Thu Jul 03, 2003 11:51 am Post subject: |
|
|
Try to assign the object with assign_by_ref
Code: | $smarty->assign_by_ref('name_of_var',$name_of_php_object); |
_________________ --
Yann RICHARD |
|
Back to top |
|
oschonrock Smarty Rookie
Joined: 08 Aug 2003 Posts: 13
|
Posted: Fri Aug 08, 2003 8:02 pm Post subject: |
|
|
and what about the reverse case? I mean using an object property as an array index.
Code: |
{if $expanded_property_id[$property->id] eq 1}
|
I can make it work with an intermediate assign like this
Code: |
{assign var='property_id' value=$property->id}
{if $expanded_property_id[$property_id] eq 1}
|
but is that necessary? or is there a magic syntax/ backtick trick etc?
Thanks
Oliver |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Fri Aug 08, 2003 8:14 pm Post subject: |
|
|
@oschonrock: unfortunately (to my knowledge) there is no trick to do this without an intermediate assign.
smarty's syntax would need bracketing to control operator-precedence to achieve what you (and i sometimes ) want. and it's a pain in the ass to do sth. like that within a regexp-based parser . |
|
Back to top |
|
oschonrock Smarty Rookie
Joined: 08 Aug 2003 Posts: 13
|
Posted: Fri Aug 08, 2003 9:08 pm Post subject: |
|
|
ok, thanks for quick reply, at least we know now. |
|
Back to top |
|
|