[TIP] cms generated items > last item styled differently

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
Post Reply
essexboyracer
Forum Members
Forum Members
Posts: 85
Joined: Wed Jun 20, 2007 5:40 pm

[TIP] cms generated items > last item styled differently

Post by essexboyracer »

I was using the excellent gallery module but wanted the output to style the last item differently, i.e. each thumb had a right margin of 5px, but I didnt want the last thumb in the row to have that, otherwise it would drop that thum to the next row and so on.

In your gallery template, insert the following:

Code: Select all

{foreach from=$images item=image name=foo}
  {if $smarty.foreach.foo.index % 4 == 3}
	<div class="img" style="margin-right: 0;">
  {else}
	<div class="img">
  {/if}
It will allow you to style the fourth image with no right margin. Found on http://www.smarty.net/manual/en/languag ... oreach.php
Last edited by essexboyracer on Sun Oct 18, 2009 11:48 am, edited 1 time in total.
applejack
Power Poster
Power Poster
Posts: 1014
Joined: Fri Mar 30, 2007 2:28 am

Re: [TIP] cms generated items > last item styled differently

Post by applejack »

You would be better to use last i.e.

Code: Select all

{foreach from=$images item=image name=foo}
  {if $smarty.foreach.foo.last}
	<div class="img" style="margin-right: 0;">
  {else}
	<div class="img">
  {/if}
{/foreach}

Website Design & Production
http://www.applejack.co.uk
Post Reply

Return to “Tips and Tricks”