1
tigums
[answered] using smarty to display multidimensional array
  • 2004/6/1 4:11

  • tigums

  • Just popping in

  • Posts: 8

  • Since: 2004/5/30


I have an array defined, and with smarty debugging on it properly shows in the popup the content of the array.

The structure of the array is

charinfo.[0-#].[first, last, home]

So when I call

$charinfo.0.first

it returns the first name of the first array inside the charinfo array.


Now to display this array, I need to travel through each [0-#] array.

<{section name=customer loop=$counter}>
    .<{
$smarty.section.customer.index}>
<{/
section}>


This does, for example if $counter = 2, display
Quote:

.0
.1


So now I have a way to cycle through the arrays 0-# (or more specifically 0-($counter-1))

but how do I add that index variable into an array call?

things I have tried, and failed with:

.<{$charinfo.($smarty.section.customer.index).first}> 
.<{
$charinfo.<{$smarty.section.customer.index}>.first}> 
.<{
$charinfo.{$smarty.section.customer.index}.first}> 
.<{
$charinfo.".$smarty.section.customer.index.".first}>
.<{
$charinfo."$smarty.section.customer.index".first}>
.<{
$charinfo.$smarty.section.customer.index.first}> **


** This one, unlike the others, didn't "nuke" the page. The paged looks normal, but still doesn't return any values



the Smarty Debug window displays nothing about the section loop, or any of the calls inside the loop, so I can't find a use for it in this situation.


Note- the leading .'s are placeholders

2
tigums
Re: using smarty to display multidimensional array
  • 2004/6/1 4:23

  • tigums

  • Just popping in

  • Posts: 8

  • Since: 2004/5/30


Ah, figured it out

Did a search and found this link
https://xoops.org/modules/newbb/viewtopic.php?topic_id=19614&forum=17#forumpost84369


so my code needed to be
<{section name=j loop=$charinfo}>
    
        .<{
$charinfo[j].first}> <br><br>

      
<{ /
section }>



It's pretty much exactly how http://smarty.php.net/manual/en/language.function.section.php (which is the resource I used to make mine section function) defines the section function, yet I, for some reason, didn't figure out what was going on. I still kinda don't, but it works.

Login

Who's Online

292 user(s) are online (187 user(s) are browsing Support Forums)


Members: 0


Guests: 292


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits