My site currently looks like this; and I would like it to look like this. But I only want the green bar on the top to be displayed if there's any news items that are active.
So I am wondering is it possible to set an if statement that check if there's any news items that are active.
[solved] if statement that checks if news items are active?
[solved] if statement that checks if news items are active?
Last edited by DoctorWho on Wed Jan 11, 2012 8:27 pm, edited 1 time in total.
CMSMS: 1.9.4.3 | PHP: 5.2.12 | MySQL: 5.0.45 | Linux
Re: an if statement that checks if any news items are active
You can try something like this...
This will only show the news item(s) if there is at least one that is active.
The other option is to insert the conditional logic into the news template. Something like this will work...
Hope this helps.
S
Code: Select all
{capture assign=my_news}{news}{/capture}
{if $my_news != ''}
{eval var=$news}
{/if}
The other option is to insert the conditional logic into the news template. Something like this will work...
Code: Select all
{if $itemcount > 0}
...code to display news items...
{/if}
S
Re: an if statement that checks if any news items are active
Thanks spcherub!
I tried it like this, but it didn't work:
So I tried it like this, and it did work:
I also tried it like this (inside news summary template), and it worked as well:
Is there any advantage or disadvantage placing the code in the main page template vs. placing the code in the news summary template?
Lastly, how do I get this to only appear on the home page?
Something like this:
or would something like this work better:
I know I can place this
in side a page, but I want this banner/marquee to appear before and outside of the main content section ( {content} )
I tried it like this, but it didn't work:
Code: Select all
{capture assign=my_news}{news}{/capture}
{if $my_news != ''}
{eval var=$news}
{/if}
Code: Select all
{capture assign=my_news}{news}{/capture}
{if $my_news != ''}
{news}
{/if}
Code: Select all
{if $itemcount > 0}
{foreach from=$items item=entry}
<p><strong><a href="{$entry->moreurl}">{$entry->title|cms_escape}</a></strong></p>
{/foreach}
{/if}
Lastly, how do I get this to only appear on the home page?
Something like this:
Code: Select all
{capture assign=my_news}{news}{/capture}
{if $my_news != '' && $node->current == "home"}
<div id=#news>{news}</div>
{/if}
Code: Select all
{capture assign=my_news}{news}{/capture}
{if $my_news != '' && $cgsimple->get_root_alias() == "home"}
<div id=#news>{news}</div>
{/if}
Code: Select all
{cms_module module="news"}
CMSMS: 1.9.4.3 | PHP: 5.2.12 | MySQL: 5.0.45 | Linux
Re: an if statement that checks if any news items are active
The first one did not work because there was a typo (my fault). It should be as follows:
It is more processing efficient this way (above) because you are not calling the News module twice.
If you are using the same template for the home page and other pages, then, you should check for the page alias (similar to one of your examples), so something like this should work.
You could also make this more flexible by checking one of the Extra Page Attributes instead of the alias. This way you can apply this logic to amy page that has a specific value in one of the Extra Page Attributes.
Given that you want to use this logic just on the home page, it is probably better (easier to read) to place the logic in the page template instead of the news template. Someone else more familiar with the backend could shed some light on which method is more "efficient".
Hope that helps.
-S
Code: Select all
{capture assign=my_news}{news}{/capture}
{if $my_news != ''}
{eval var=$my_news}
{/if}
If you are using the same template for the home page and other pages, then, you should check for the page alias (similar to one of your examples), so something like this should work.
Code: Select all
{if $page_alias == "home"}
{capture assign=my_news}{news}{/capture}
{if $my_news != ''}
<div id=#news>{eval var=$my_news}</div>
{/if}
{/if}
Given that you want to use this logic just on the home page, it is probably better (easier to read) to place the logic in the page template instead of the news template. Someone else more familiar with the backend could shed some light on which method is more "efficient".
Hope that helps.
-S
Re: an if statement that checks if any news items are active
Thanks again spcherub! 

CMSMS: 1.9.4.3 | PHP: 5.2.12 | MySQL: 5.0.45 | Linux