If else condition in smarty.tpl for nth-child list / div

I work with Smarty. I want to add a condition if elseto my file .tplfor n / i-child classes li / div.

I have two image sizes. I want to use a 600px image in the first li, 400px image in the 2nd and 3rd and again a 600px image in the 4th li, etc.

I am currently using the CSS3 selector nth-childand using scaled images of 400 pixels. But the loading time is bad. I want to use smaller images if necessary.

I think it is very difficult. It?

Here is my code:

<img src="{$purl}/thumbs/{$posts[i].pic}" alt="{$posts[i].story|stripslashes}" />

and exists in a loop {section name=i loop=$posts} {include file="posts.tpl"} {/section}inside posts.tpl.

+5
source share
1 answer

cycle will be helpful.

Suppose you have an array with the path to images stored in two fields: image-600and image-400:

{foreach from=$images item=image}
    {capture assign=currentKey}image-{cycle values='600,400,400'}{/capture}
    <li><img src="{$image[$currentKey]}" alt="{$image.title}" /></li>
{/foreach}

in your case it will look something like this:

{section name=i loop=$posts}
   {capture assign=thumbSize}{cycle values='big,small,small'}{/capture}
   <img src="{$purl}/thumbs/{if $thumbSize eq 'big'}{$posts[i].pic}{else}s-{$r[i].pic}{/if}" alt="{$posts[i].story|stripslashes}" />
{/section}
+2
source

All Articles