I wrote a quick little plugin to calculate the modulo value and figured I’d share it here.
In computing, the modulo operation finds the remainder of division of one number by another.
Given two numbers, a (the dividend) and n (the divisor), a modulo n (abbreviated as a mod n) is the remainder, on division of a by n. For instance, the expression “7 mod 3” would evaluate to 1, while “9 mod 3” would evaluate to 0. Although typically performed with a and n both being integers, many computing systems allow other types of numeric operands.
Parameters
1) Dividend (required) 2) Divisor (required)
{exp:modulo dividend="dividend" divisor="divisor"}For example:
{exp:modulo dividend="3" divisor="3"} => 0
{exp:modulo dividend="4" divisor="3"} => 1
{exp:modulo dividend="5" divisor="3"} => 2
{exp:modulo dividend="6" divisor="3"} => 0Hope it saves you some time…..
Best, David
Personally I use the switch tag to handle that issue. If I have a row with 3 items and I want the third to have a certain class, ‘endrow’ for example, I would do something like this:
<div class="normalclass {switch='||endrow'}">
path/to/image/
</div>The result would be:
<div class="normalclass">
path/to/image/
</div>
<div class="normalclass">
path/to/image/
</div>
<div class="normalclass endrow">
path/to/image/
</div>Hope that helps!
Best, David
First off - David thanks for a great plugin. I’ve done this in the past with PHP but it really annoys me doing things like that. I’ve always meant to make a plugin to do this and just never got around to it so this is great, thanks.
I often use this (with php) to add classes to remove padding on the last image in a gallery in the weblog entries loop. Can you use it like this (I haven’t tried)?{if {exp:modulo dividend="{count}" divisor="3"} = 0}class="last"{/if}
Should work if you do it like this :
{if "{exp:modulo dividend="{count}" divisor="3"}" == "0"}class="last"{/if}Best wishes,
Mark
OK I have found that neither of these solutions work…
Here is my code for both solutions. One using the new Modulo Operator.
Just to say the switch tag is not appropriate for my website layout.
If anyone could she some light it would be appreciated.
{exp:weblog:entries weblog="links" sort="asc" disable="categories|member_data|pagination|trackbacks|comments"}
<!-- Link -->
<div class="{switch="grid_3 alpha link|grid_3 link|grid_3 omega link"}">
<h1>{title}</h1>
<h3>{link_url}</h3>
{link_description}
</div>
<!-- // Link -->
{if "{exp:modulo dividend="{count}" divisor="3"}" == "0"}
<div class="clear"></div>
{/if}
{/exp:weblog:entries}{exp:weblog:entries weblog="links" sort="asc" disable="categories|member_data|pagination|trackbacks|comments"}
<!-- Link -->
<div class="{switch="grid_3 alpha link|grid_3 link|grid_3 omega link"}">
<h1>{title}</h1>
<h3>{link_url}</h3>
{link_description}
</div>
<!-- // Link -->
{if count == 3 || count == 6 || count == 9 || count == 12 || count == 15 || count == 18 || count == 21}
<div class="clear"></div>
{/if}
{/exp:weblog:entries}Try this:
{exp:weblog:entries weblog="links" sort="asc" disable="categories|member_data|pagination|trackbacks|comments"}
<!-- Link -->
<div class="{switch="grid_3 alpha link|grid_3 link|grid_3 omega link"}">
<h1>{title}</h1>
<h3>{link_url}</h3>
{link_description}
</div>
<!-- // Link -->
{switch="||<div class="clear"></div>"}
{/exp:weblog:entries}Yeah, change the quotes to single quotes. I’d also add comments inside the div for better browser compatibility.
{exp:weblog:entries weblog="links" sort="asc" disable="categories|member_data|pagination|trackbacks|comments"}
<!-- Link -->
<div class="{switch="grid_3 alpha link|grid_3 link|grid_3 omega link"}">
<h1>{title}</h1>
<h3>{link_url}</h3>
{link_description}
</div>
<!-- // Link -->
{switch="||<div class='clear'><!-- --></div>"}
{/exp:weblog:entries}Yes that worked a treat many thanks.
I also tried a method using the if tag which was…
{if count == 3 || count == 6}
do this...
{/if}This one was odd because it worked in some places in my site but not in others, and I could not understand why as the code was all identical.
Many thanks fro your help, much appreciated.
I would love to see the plug-in you created in action. Perhaps you should put up online somewhere some working examples so non developers like me can grasp what it can be used for?
M.
Yeah, change the quotes to single quotes. I’d also add comments inside the div for better browser compatibility.{exp:weblog:entries weblog="links" sort="asc" disable="categories|member_data|pagination|trackbacks|comments"} <!-- Link --> <div class="{switch="grid_3 alpha link|grid_3 link|grid_3 omega link"}"> <h1>{title}</h1> <h3>{link_url}</h3> {link_description} </div> <!-- // Link --> {switch="||<div class='clear'><!-- --></div>"} {/exp:weblog:entries}
Hmm - it’s not working for - it does not output any div clear?
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.