|
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 |
HockS Smarty n00b
Joined: 08 Nov 2019 Posts: 3
|
Posted: Fri Nov 08, 2019 10:40 am Post subject: Read multidimensional array in smarty |
|
|
Hi, I have a problem reading an array in the loop.
I have the following variable:
variable: $shop.hours
value: [["9 - 14 \/ 16 - 20"],["9 - 14 \/ 16 - 20"],["9 - 14 \/ 16 - 20"],["9 - 14 \/ 16 - 20"],["9 - 14 \/ 16 - 20"],["9 - 14"],["Close"]] [note] =>
When I try to read it in the loop, it returns the result of the complete variable.
Example:
Code: | {foreach item=timetable from=$shop.hours}
{$timetable}
{/foreach} |
This is what returns me: [["9 - 14 \/ 16 - 20"],["9 - 14 \/ 16 - 20"],["9 - 14 \/ 16 - 20"],["9 - 14 \/ 16 - 20"],["9 - 14 \/ 16 - 20"],["9 - 14"],["Close"]] [note] =>
I am sorry for my bad english.
Edit: I was wrong, the correct value of the variable is [["9 - 14 \/ 16 - 20"],["9 - 14 \/ 16 - 20"],["9 - 14 \/ 16 - 20"],["9 - 14 \/ 16 - 20"],["9 - 14 \/ 16 - 20"],["9 - 14"],["Close"]]
Last edited by HockS on Mon Nov 11, 2019 8:00 am; edited 1 time in total |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Fri Nov 08, 2019 7:40 pm Post subject: |
|
|
Code: | {$shop.hours|var_dump} |
?? |
|
Back to top |
|
HockS Smarty n00b
Joined: 08 Nov 2019 Posts: 3
|
Posted: Mon Nov 11, 2019 7:56 am Post subject: |
|
|
AnrDaemon wrote: | Code: | {$shop.hours|var_dump} |
?? |
This is the dump: string(134) "[["9 - 14 \/ 16 - 20"],["9 - 14 \/ 16 - 20"],["9 - 14 \/ 16 - 20"],["9 - 14 \/ 16 - 20"],["9 - 14 \/ 16 - 20"],["9 - 14"],["Close"]]" |
|
Back to top |
|
HockS Smarty n00b
Joined: 08 Nov 2019 Posts: 3
|
Posted: Mon Nov 11, 2019 9:27 am Post subject: |
|
|
I created a temporary patch ... it works, but I think it's not the right way. I would like it to work with smarty alone.
Code: |
<script>
var timetable = {$shop.hours nofilter};
{literal}
for (var i = 0; i < timetable.length; i++) {
document.write(timetable[i]);
}
{/literal}
</script>
|
|
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Fri Nov 15, 2019 9:43 pm Post subject: |
|
|
Quote: | This is the dump: string(134) |
It's a string, not an array. So, nothing to read from.
If you think that's not right, you could try to use json_decode on it. |
|
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
|