/    Sign up×
Community /Pin to ProfileBookmark

Smarty: count to line Break

Hello guys,

Im using an array to display menu items, it looks like this:

[code]
{foreach from=$aMenuItems item=aMenuItem}
<td class=”menu” onclick=”javascript:window.location.href='{$aMenuItem.url}’;” onmouseover=”this.className=’menu2′;” onmouseout=”this.className=’menu’;”>
<a href=”{$aMenuItem.url}”>{$aMenuItem.title}</a>
</td>
{/foreach}
[/code]

This part is working perfectly.

But now I realize I have too many items in the menu and want to insert a new row.
Im using Smarty obviously.

so I tried using [b/assign[/b] in the php file but its not working too well so figured it would be easier to just use a counter and when it reaches say 10 elements to just output the end of the row and the start of a new one (</tr></tr>). ==> I realize this would break the table structure but thats not important, once I get this step working I can output a new table if needed.

So here’s my other attempt:

[code=html]
{counter start=0 skip=1}

{foreach from=$aMenuItems item=aMenuItem}
{if counter == ’10’}
</tr><tr>
{else}
{counter}
{/if}

<td class=”menu” onclick=”javascript:window.location.href='{$aMenuItem.url}’;” onmouseover=”this.className=’menu2′;” onmouseout=”this.className=’menu’;”>
<a href=”{$aMenuItem.url}”>{$aMenuItem.title}</a>
</td>
{/foreach}
[/code]

I tried with and without single quotes on the [i]counter == ’10’[/i] and it made no difference, its never going to the true part of the if and I dont know why. Its always outputting the counter (that I understand why, did it on purpose to test it)

Can somebody please tell me how to do this?

thank you for your time ?

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@avaMar 02.2007 — Comparisons in Smarty are written with the [I]eq[/I] keyword.

So that would mean you would have to write:
[code=php]{if counter eq 10}[/code]
Copy linkTweet thisAlerts:
@purefanauthorMar 02.2007 — hey ava! thank you for posting.

however im afraid it didnt help.... im not sure what could it be at this point...

maybe if you post this idea on a valid example...

thank you again!
×

Success!

Help @purefan spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...