简体   繁体   中英

SMARTY - maximum in section doesn't work as it should

I've got a problem with my section loops. I have 3 different section loops and I have to display only 5 results (doesn't matter if first section loop's got 5 results or 2results from first, 1 from second and 2 from last section loop). Max in first loop is set to 5 and inside I add counter to check if there are less than 5 results if there are less results than 5 I start second loop and Now there is a problem when i set max in second loop max-(value of my counter) it ignore this value and always display 5 results from second loop, third section loop is not displayed, that's ok, but second should have max set to 1. Please excuse my bad english. Thank you very much for advice. Have a nice day.

Demo: Upcoming events module on right bottom

Code:

{assign var="counter" value=1}
{section name=ArtCat2 loop=$ArtCat2 max=5}
    {assign var="cc" value=$counter++}
    CC:{$cc}
    <br/>
    <br/>
    {foreach from=$category item=CAT}
        <div>
            <h2 class="h2">
                <a href="/{$country}/{$lang}/{$CAT.ID}_{$CAT.friendlyTitle}/{$ArtCat2[ArtCat2].ID}_{$ArtCat2[ArtCat2].friendlyTitle}.html?do=article">
                    {$ArtCat2[ArtCat2].Title}
                </a>
            </h2>
                                            <span class="small2">
                                            <b>{$ArtCat2[ArtCat2].Date} | {$ArtCat2[ArtCat2].Location}</b>
                                            </span>
            {$ArtCat2[ArtCat2].ShortText}
            <a class="link3"
               href="/{$country}/{$lang}/{$CAT.ID}_{$CAT.friendlyTitle}/{$ArtCat2[ArtCat2].ID}_{$ArtCat2[ArtCat2].friendlyTitle}.html?do=article">
                <span class="small2"></span></a>
        </div>
        <br class="clear"/>
        <br/>
    {/foreach}
    {* Online *}
{/section}
{if $cc >= 5}
{else}
    {section name=ArtCat3 loop=$ArtCat3 max=5-$cc}
        {assign var="cc2" value=$counter++}
        CC: {$cc}
        <br/>
        <br/>
        CC2:{$cc2}
        <br/>
        <br/>
        {foreach from=$category item=CAT}
            <div>
                <h2 class="h2">
                    <a href="/{$country}/{$lang}/{$CAT.ID}_{$CAT.friendlyTitle}/{$ArtCat3[ArtCat3].ID}_{$ArtCat3[ArtCat3].friendlyTitle}.html?do=article">
                        {$ArtCat3[ArtCat3].Title}
                    </a>
                </h2>
                                            <span class="small2">
                                            <b>{$ArtCat3[ArtCat3].Date} | {$ArtCat3[ArtCat3].Location}</b>
                                            </span>
                <br/>
                {$ArtCat3[ArtCat3].ShortText}
                <a class="link3"
                   href="/{$country}/{$lang}/{$CAT.ID}_{$CAT.friendlyTitle}/{$ArtCat3[ArtCat3].ID}_{$ArtCat3[ArtCat3].friendlyTitle}.html?do=article">
                    <span class="small2"></span></a>
            </div>
            <br class="clear"/>
            <br/>
        {/foreach}


    {/section}
{/if}
{* International *}
{if $cc+$cc2 >= 5}
{else}
    {section name=ArtCat4 loop=$ArtCat4 max=5-$cc+$cc2}
        {foreach from=$category item=CAT}
            <div>
                <h2 class="h2">
                    <a href="/{$country}/{$lang}/{$CAT.ID}_{$CAT.friendlyTitle}/{$ArtCat4[ArtCat4].ID}_{$ArtCat4[ArtCat4].friendlyTitle}.html?do=article">
                        {$ArtCat4[ArtCat4].Title}
                    </a>
                </h2>
                                            <span class="small2">
                                            <b>{$ArtCat4[ArtCat4].Date} | {$ArtCat4[ArtCat4].Location}</b>
                                            </span>
                <br/>
                {$ArtCat4[ArtCat4].ShortText}
                <a class="link3"
                   href="/{$country}/{$lang}/{$CAT.ID}_{$CAT.friendlyTitle}/{$ArtCat4[ArtCat4].ID}_{$ArtCat4[ArtCat4].friendlyTitle}.html?do=article">
                    <span class="small2"></span></a>
            </div>
            <br class="clear"/>
            <br/>
        {/foreach}
    {/section}
{/if}

I cannot at the moment test it, but I think the problem is in that line:

{section name=ArtCat4 loop=$ArtCat4 max=5-$cc+$cc2}

It should be rather:

{section name=ArtCat4 loop=$ArtCat4 max=5-$cc-$cc2}

because earlier you check condition {if $cc+$cc2 >= 5}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM