• twitter image
  • facebook image
  • youtube image
  • linkedin image
Language: CMS Made Simple Czech CMS Made Simple France CMS Made Simple Hungary CMS Made Simple Russia CMS Made Simple Netherlands

All times are UTC




Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 10 posts ] 
Author Message
 Post subject: [SOLVED] Show news only if news are active
PostPosted: Wed Nov 13, 2013 4:09 pm 
Offline
Power Poster
Power Poster
User avatar

Joined: Fri Jul 25, 2008 10:13 am
Posts: 283
Location: Zug, Switzerland
I was surprised to discover the {news} tag does show up the summary template even without any article active.

I found an example to only show news if there are news articles active. However, this does not work:

Quote:
{capture assign=news_there}{news}{/capture}
{if $news_there}
{news}
{/if}


It still shows the summary template div and news box, just without articles. But I want to not show anything with no active article.

Any other solution? Maybe an "if news active" in the template?


Last edited by thomahawk on Fri Nov 15, 2013 11:54 am, edited 1 time in total.

Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: Show news only if news are active
PostPosted: Wed Nov 13, 2013 4:29 pm 
Offline
Dev Team Member
Dev Team Member
User avatar

Joined: Mon Jan 29, 2007 4:47 pm
Posts: 1739
There have been a few posts about this on this forum before. To cut a long story short: It all depends on the template (in this case the summary one). The default one, and most of the customized ones, don't return empty even if there are no news to show. These usually return, at the very least, some html tags (div's etc). You need to check the template and make it return empty if there are no news.
Which goes to say that it could, and should, all be done at the summary template level and avoid that (unnecessary IMO) last check on the main page template. HTH.

_________________
"There are 10 types of people in this world, those who understand binary... and those who don't."
* by the way: English is NOT my native language (sorry for any mistakes...).


Code of Conduit | CMSMS Docs
Help Support CMSMS
My developer Page on the Forge | Yet another blog about CMSMS

GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!



Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: Show news only if news are active
PostPosted: Wed Nov 13, 2013 5:05 pm 
Offline
Dev Team Member
Dev Team Member

Joined: Mon Nov 28, 2011 9:29 am
Posts: 3061
Location: The Netherlands
http://forum.cmsmadesimple.org/viewtopic.php?f=20&t=68417

Check for $count variable.

Code:
{if $count->value gt 0} //not sure, check if that works


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: Show news only if news are active
PostPosted: Fri Nov 15, 2013 7:56 am 
Offline
Power Poster
Power Poster
User avatar

Joined: Fri Jul 25, 2008 10:13 am
Posts: 283
Location: Zug, Switzerland
Hi Velden. Thanks for your useful post.

I made the template like this:

Code:
{if $count->value gt 0}
<div class="newsbox">
<div class="newsboxtitel">NEWS</div>

{foreach from=$items item=entry}
<div class="newsboxtext">
<span class="newsdate">{$entry->postdate|cms_date_format}</span><br>
{$entry->summary|cms_escape:htmlall}<br>
<a href="{$entry->moreurl}"> ZUM ARTIKEL</a></div>
{/foreach}

<div style="clear:both"></div>
</div>
{else}
Test
{/if}


From Debug, $count is available and shows "1", nevertheless nothing from this template is shown, with or without news articles active. Is something missing?

Update: Even when I make 2 articles active I see Debug shows $count ->value = 1. But I see $itemcount does react correctly and shows a value of 0 or 1 depending on the amount of activated articles, so I changed the summary code to: {if $itemcount->value gt 0}, but still the template does never display. Only the else statement "Test" shows up.

I also tried it reversed:
Code:
{if $itemcount->value == 0}

{else}
<div class="newsbox">
<div class="newsboxtitel">NEWS</div>

{foreach from=$items item=entry}
<div class="newsboxtext">
<span class="newsdate">{$entry->postdate|cms_date_format}</span><br>
{$entry->summary|cms_escape:htmlall}<br>
<a href="{$entry->moreurl}"> ZUM ARTIKEL</a></div>
{/foreach}

<div style="clear:both"></div>
</div>

{/if}


With articles activated, does also not show them.

Thanks
Thom


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: Show news only if news are active
PostPosted: Fri Nov 15, 2013 11:13 am 
Offline
Dev Team Member
Dev Team Member

Joined: Mon Nov 28, 2011 9:29 am
Posts: 3061
Location: The Netherlands
Stole this from another template:

Code:
{if $items|@count > 0}


Didn't check it myself but it seems to make sense.


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: Show news only if news are active
PostPosted: Fri Nov 15, 2013 11:53 am 
Offline
Power Poster
Power Poster
User avatar

Joined: Fri Jul 25, 2008 10:13 am
Posts: 283
Location: Zug, Switzerland
Velden. Many thanks! Thats it. Now it works. I made it like this:

Code:
{if $items|@count == 0}
nada
{else}

{foreach from=$items item=entry}
{$entry->postdate|cms_date_format}<br>
{$entry->summary|cms_escape:htmlall}<br>
<a href="{$entry->moreurl}"> MORE</a>
{/foreach}

{/if}



(I really don't understand why the main cmsms news info page http://docs.cmsmadesimple.org/modules/core/news has an example for this (on the bottom of the page) which does not work.)


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: [SOLVED] Show news only if news are active
PostPosted: Fri Nov 15, 2013 12:41 pm 
Offline
Dev Team Member
Dev Team Member
User avatar

Joined: Wed Apr 23, 2008 7:53 am
Posts: 7635
Location: The Netherlands
We do have a feedback form...

_________________
Image

Did my post help you solving a problem at your (customers) website and it saved you many hours of work? Great!! Consider buying me a cup of coffee in return!



Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: Show news only if news are active
PostPosted: Fri Nov 15, 2013 1:37 pm 
Offline
Dev Team Member
Dev Team Member

Joined: Mon Nov 28, 2011 9:29 am
Posts: 3061
Location: The Netherlands
thomahawk wrote:
(I really don't understand why the main cmsms news info page http://docs.cmsmadesimple.org/modules/core/news has an example for this (on the bottom of the page) which does not work.)


That example would work now probably.

Code:
{capture assign=news_there}{news}{/capture}
    {if $news_there}
    <div id="news">
    <h3>News</h3>
    {news}
    </div>
    {/if}


But I don't think it's a very good example because:
- The current Sample template will always have output even if item count is zero (which makes this example useless)
- Output of {news} is captured and assigned, and if it has content {news} is called again. Unnecessary because the $news_there variable already contains what you want to show so better use {$news_there}

Example might have worked in older versions of News module with other sample templates.


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: [SOLVED] Show news only if news are active
PostPosted: Sun Nov 17, 2013 8:36 am 
Offline
Power Poster
Power Poster
User avatar

Joined: Fri Jul 25, 2008 10:13 am
Posts: 283
Location: Zug, Switzerland
Strange. Someone moved this topic into the wrong forum section. This does not fit in "the lounge".


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
 Post subject: Re: [SOLVED] Show news only if news are active
PostPosted: Thu Nov 21, 2013 3:09 pm 
Offline
Dev Team Member
Dev Team Member
User avatar

Joined: Sat Apr 18, 2009 10:09 pm
Posts: 1425
Location: Maidenhead, UK
Agreed; moved :)


Top
  Profile  
 
Share On:
Share on Facebook Share on Twitter Share on Google+
Display posts from previous:  Sort by  
Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 10 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Hosting Nation - Managed CMSMS Hosting