Page 1 of 1

{if checkbox->value} display 1 news.

Posted: Mon Dec 10, 2012 11:38 am
by piphansdk
When i submit an article i have a checkbox, for important news.
I need to make an summary template, that is showing 1 article, if the checkbox is checked.

Code: Select all

{foreach from=$items item=entry} 
{if $entry->fieldsbyname.tophistorie->value}
<a class="thlink" href="{$entry->moreurl}">
<div id="thlinkholder">
<div id="thtextholder">
{$entry->title|cms_escape}
</div>
</div>
</a>
<div id="thimgholder">
<img src="{$entry->file_location}/{$entry->fieldsbyname.image->value}" height="100%" width="100%"/>
</div>
{/if}
{/foreach}
i have made this one. It is working fine, but of course, if i have 5 news with the checkbox checked, it will post all 5, and i only want one.
so if i write {news summarytemplate="template" number="1"}
it is working fine, but if the latest article havent a checked checkbox, it will post no articles :( any idea?

Re: {if checkbox->value} display 1 news.

Posted: Mon Dec 10, 2012 2:13 pm
by uniqu3
If you are using CMSMS 1.11.x which is using Smarty3 template engine you can look here http://www.smarty.net/docs/en/language. ... ruct.break

Re: {if checkbox->value} display 1 news.

Posted: Tue Dec 11, 2012 9:16 am
by piphansdk
Hi :) thank you for the anwser, but i am sorry, i can not understand the codes :(

can you please help me out?

Re: {if checkbox->value} display 1 news.

Posted: Tue Dec 11, 2012 9:40 am
by uniqu3
Assuming tophistorie field is your checkbox?

Code: Select all

{foreach from=$items item=entry} 
{if $entry->fieldsbyname.tophistorie->value != 1}
    {continue}
{/if}
{if $entry@index > 1}
    {break}
{/if}
<a class="thlink" href="{$entry->moreurl}">
<div id="thlinkholder">
<div id="thtextholder">
{$entry->title|cms_escape}
</div>
</div>
</a>
<div id="thimgholder">
<img src="{$entry->file_location}/{$entry->fieldsbyname.image->value}" height="100%" width="100%"/>
</div>
{/if}
{/foreach}
Untested but should be close

Re: {if checkbox->value} display 1 news.

Posted: Tue Dec 11, 2012 10:04 pm
by piphansdk
thank you so much, removed the {/if} and it worked like a charm :) Have a pleasant day :)