 |
Smarty
The discussions here are for Smarty, a template engine for the PHP programming language. Dedicated server web hosting provided by Guru-host.eu. |
| View previous topic :: View next topic |
| Author |
Message |
insightcreative Smarty n00b
Joined: 23 Apr 2012 Posts: 2
|
Posted: Mon Apr 23, 2012 8:22 am Post subject: Array within an array |
|
|
Hi
I have to change a bit of functionality on a site. At the moment, there is an array with about 8 items in it. I need to display the items in a certain order and also break into the array to display some other stuff first.
So, it's go something like:
2
3
1
Some other bits
8
5
6
7
4
It's someone else's code and was obviously built for flexibility but I don't need that so my plan is to display each element in the array manually rather than looping through it.
I've managed to do part of it:
| Code: | | {$setall.5.attr_value} |
But some of the positions in the array are also arrays which I do need to loop through.
So, if position 5 is a value then I'm fine. But what if position 5 is another array? How can I loop through that to get all the values out no matter how many there are?
This is my first foray into smarty templates so any help would be gratefully received!
Best regards
Andy Jacobs |
|
| Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 4200 Location: Hamburg / Germany
|
Posted: Wed Apr 25, 2012 9:09 am Post subject: |
|
|
The following should do the job
| Code: | {foreach $setall.5 as $value}
{$value}
{/foreach} |
|
|
| Back to top |
|
insightcreative Smarty n00b
Joined: 23 Apr 2012 Posts: 2
|
Posted: Wed Apr 25, 2012 12:27 pm Post subject: Still not right... |
|
|
Hi
Thanks for that but it still seems to be one level out. If you have a look at:
http://j412.workinprogress.co.uk/component/jomdirectory/23-Friendship-Travel
You'll see that I've put your code in (just changed the 5 to a 0). Within that there is another array.
At position 3, it just says 'attr_value => "array"'. In there, is British Isles Europe as you can see at the top of the page.
I guess I want to get the array at position 3 of position 0 of the first array.
In my head, this should look like:
| Code: | | {foreach $setall.0.3 as $value} |
But that doesn't work :/
The bit that displays the output at the top is like this:
| Code: | {foreach from=$setall item=item}
{if $item.req_type != 6}
{if $item.attr_value}
<div class="detailed_line" >
<p>
<label>{$item.name}</label>
{$item.attr_value|JView:$item.attr_id:$data->id:$item.type:$item.req_type} </p>
</div>
{/if}
{/if}
{/foreach} |
This displays everything apart from the long description. What I need to do is display the fields in the setall array in a certain order. I can do that.
BUT... I need to insert the long description part way through so it might go:
{$setall.2.attr_value}<br />
{$setall.4.attr_value}<br />
{$setall.3.attr_value}<br />
LONG Description
{$setall.1.attr_value}<br />
{$setall.5.attr_value}<br />
This works fine as long as {$setall.2.attr_value} isn't another array.
Best regards
Andy |
|
| 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
|