|
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 |
c0p0n Smarty n00b
Joined: 15 Jul 2003 Posts: 4
|
Posted: Tue Sep 30, 2003 2:27 pm Post subject: Operations with array indexes |
|
|
I wanna do this:
Code: | {section name=i loop=$datos}
{if ($datos[i].idmedia != $datos[i-1].idmedia)}
<b>CD: {$datos[i].idmedia}</b>
{/if}
<p>
{$datos[i].path}/{$datos[i].name}
</p>
{/section} |
The problem is at $datos[i-1].idmedia stuff, it seems that I cannot do it. I've tried also:
Code: | {section name=i loop=$datos}
{assign var="j" value="$i-1"}
{if ($datos[i].idmedia != $datos[j].idmedia)}
<b>CD: {$datos[i].idmedia}</b>
{/if}
<p>
{$datos[i].path}/{$datos[i].name}
</p>
{/section} |
With no luck.
The thing that I want to do is simple: if the content of that var is not equal to the content of the same var, but on the previous loop, the template should show a text.
(the source is a list of archives, ordered by CD-ROM numbers. If the actual CD is not the same as the previous, it begins a new CD-ROM files listing so it should display the actual CD).
Edit: oh! I forgot!. Smarty 2.5.0 |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Tue Sep 30, 2003 3:49 pm Post subject: Re: Operations with array indexes |
|
|
maybe sth. like this:
(untested)
Code: | {assign var=recent_id value=-1} {* some "illegal" id *}
{section name=i loop=$datos}
{if ($datos[i].idmedia != recent_id)}
<b>CD: {$datos[i].idmedia}</b>
{assign var=recent_id value=$datos[i].idmedia}
{/if}
<p>
{$datos[i].path}/{$datos[i].name}
</p>
{/section} |
|
|
Back to top |
|
c0p0n Smarty n00b
Joined: 15 Jul 2003 Posts: 4
|
Posted: Tue Sep 30, 2003 4:12 pm Post subject: |
|
|
thank U sir! it worked, with a little modification:
Code: | {assign var=recent_id value=-1}
{section name=i loop=$datos}
{if ($datos[i].idmedia != $recent_id)}
<b>CD: {$datos[i].idmedia}</b>
{assign var=recent_id value=$datos[i].idmedia}
{/if}
<p>
{$datos[i].path}/{$datos[i].name}
</p>
{/section} |
I had to put the first {assign} statement before the loop, because it reseted to -1 every time the loop went back to beginning (I think that that was the way you thought it, but you wrote it badly).
again, thanx! ;D |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Tue Sep 30, 2003 4:51 pm Post subject: |
|
|
what are you smokin'? of course i initilalized recent_id *outside* of the section. |
|
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
|