1
TheFinni
<{ foreach FIRST }> followed by <{ foreach REMAINDER }>
  • 2004/10/12 5:05

  • TheFinni

  • Just popping in

  • Posts: 75

  • Since: 2003/11/25


Hello,
I was wondering if someone could help me with this issue?

I would like to know if there is a way to use the;

<{foreach item=articles from=$articles}>
title 1
title 2
title 3
<{/foreach}>

and make it like:

<{foreach FIRST item=articles from=$articles}>
title 1
storytext
perhaps displaying an image
<{/foreach}>

<{foreach REMAINDER item=articles from=$articles}>
title 2
title 3
<{/foreach}>

If I could do this I could get more creative with how the templates work.

Thanks for any ideas you can provide.

2
Mithrandir
Re: <{ foreach FIRST }> followed by <{ foreach REMAINDER }>

<{counter assign="articlecount" print=false}>
<{foreach 
item=article from=$articles}>
    <{
counter}>
    <{
$article.title}>
    <{if 
$articlecount == 1}>
         <!--
storytextperhaps an image-->
    <{/if}>
<{/foreach}>

3
TheFinni
Re: followed by
  • 2004/10/17 9:02

  • TheFinni

  • Just popping in

  • Posts: 75

  • Since: 2003/11/25


Mithrandir,
Thank you again for your expert advice! I had to play with your advice a little since I didn't completly understand it first...

I found some of your other advice on the forum and thought that perhaps you had placed the <{counter}> in the wrong place when offering me your help.

Here's the link to Mithrandir's other advice in case someone else is reading this post:

https://xoops.org/modules/newbb/viewtopic.php?topic_id=16684&forum=20

I am also going to explain briefly what I did and also post my code.

Basically, I didn't understand the counter assign parameter and had to do some study on Smarty's website:

http://smarty.php.net/manual/en/language.function.counter.php

What I realized is it doesn't matter what name I assign the counter. So I chose my own name.

I also couldn't get the prper numbers and hence my unique first article didn't show up the way I wanted. Therefore I tried to see what numbers I got out by using this in my template:

<{$storycount}>

And for some strange reason my first article had a number of 2 and my second a number of 3.

I managed to change this by adding to the counter assign these parameters: start=1 skip=1 (see Smarty website).

With that said...My unique recent news block article template looks like this:

Quote:
<{counter assign="storycount" print=false start=1 skip=1}>
<{foreach item=news from=$block.stories}>
<{if $storycount == 1}><p><a href="<{$xoops_url}>/modules/news/article.php?storyid=<{$news.id}>"><{$news.artimage}></a><strong><{$news.title}></strong> : <{$news.introtext}><a href="<{$xoops_url}>/modules/news/article.php?storyid=<{$news.id}>">[read more]</a> (<{$news.date}>)</p><p><strong>Other new headlines:</strong><br /><{/if}><{if $storycount > 1}>-<a href="<{$xoops_url}>/modules/news/article.php?storyid=<{$news.id}>"><{$news.title}></a> (<{$news.date}>)<br /><{/if}>
<{counter}>
<{/foreach}></p>


My website is not done yet so I can post a link but will do so another day.

Hopefully this helps someone else!

Thanks!

Login

Who's Online

211 user(s) are online (146 user(s) are browsing Support Forums)


Members: 0


Guests: 211


more...

Donat-O-Meter

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

Latest GitHub Commits