tags:

views:

371

answers:

4

I have an array to loop in smarty. My array look like this: Array( [0]=>( [title] = 'some title' [url] = 'image url' ) )....

I loop it in file .tpl and I just want to get top 3 result from this array. My array has the number of item larger than 3. I'm a beginner of smarty someone help me fix this problem. Thank you very much for reading my situation!!

+1  A: 

Use {section}: http://www.smarty.net/manual/en/language.function.section.php

FractalizeR
Thank you Fractalize, now I can do it!
gacon
Welcome! Please mark one of the answers here as "accepted"
FractalizeR
A: 

I have no clue about Smarty, but...

...If you're interested in just the first three elements of a large array, why don't you use a for loop instead of a foreach?

Roberto Aloi
uh I quite lazy to change my code Roberto, but if I have no wayout may be I will..
gacon
A: 
Kailash Badu
A: 

I have to out put top 3 results from my array with three difference div layout. The first div is the biggest and the other two div under it in the same row. I add this item array['stt'] = 0 array['stt'] = 1 and in tpl I check {if $array.stt == 1} or {$array.stt == 0} to write out the div with the class I want, I think its not the best way but I can work exactly what I want!! @Kailas Badu: you write carefully and easy to know, thank you very much!

gacon