|
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 |
Chiuchu Smarty n00b
Joined: 03 Apr 2008 Posts: 4
|
Posted: Thu Apr 03, 2008 2:00 pm Post subject: [FIXED] "." in an array's name with smarty... |
|
|
Hi,
In php, I have this array.
<?php
$var = array();
//...
$var[0]['X.title'] = "AZERTY";
$var[1]['X.title'] = "UIOPQS";
$var[2]['X.title'] = "DFGHJK";
$smarty->assign("var", $var);
?>
With smarty, i would like to print these strings, my delimters are "{{" and "}}", these scripts aren't working :
{{section name=x loop=$var}}
{{$var[x].`X.title`}}
{{/section}}
{{section name=x loop=$var}}
{{$var[x].X.title}}
{{/section}}
{{section name=x loop=$var}}
{{$var[x]['X.title']}}
{{/section}}
You surely want to know why do I use these vars. It's because I have a complexe sql query where X is an alias and title is a column of a table.
What have I to do ?
Thanks.
PS : please excuse my bad english, i'm french...
Last edited by Chiuchu on Thu Apr 03, 2008 2:57 pm; edited 1 time in total |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Thu Apr 03, 2008 2:47 pm Post subject: |
|
|
The problem is the "." in "X.title" as array index. The "." is used in the SMARTY syntax as separator for levels of array indexes.
Here is a work around
Code: |
{{assign var=foo value="X.title"}}
{{section name=x loop=$var}}
{{$var[x].$foo}}
{{/section}} |
|
|
Back to top |
|
Chiuchu Smarty n00b
Joined: 03 Apr 2008 Posts: 4
|
Posted: Thu Apr 03, 2008 2:55 pm Post subject: |
|
|
It's working !! Thank you very much ! |
|
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
|