[Solved] Conditional issue

For discussion and questions related to CMS Specific templates and stylesheets (CSS), and themes. or layout issues. This is not a place for generic "I don't know CSS issues"
luya
Forum Members
Forum Members
Posts: 91
Joined: Wed Jan 23, 2013 1:34 am

[Solved] Conditional issue

Post by luya »

Using the following conditional code on my website: http://cwmag.ca/stg

Code: Select all

{capture assign="news_there"}{news}{/capture} 
<h4>{breadcrumbs root="home" starttext="You are visiting "}</h4>
{if $news_there}
{news category="*Society*" detailpage="society" summarytemplate="cw-news-no-category-tag" articleid="-1"}
{else}
<h2>No article on {title} section</h2>
<p>We are sorry there is no published articles in this section. Please look at other pages at this time and come back again.</p>
{/if}
...display a blank content instead of the comment from the description should the news content is empty. Any hint what went wrong?
Last edited by luya on Sat Nov 02, 2013 5:14 pm, edited 1 time in total.
User avatar
Rolf
Power Poster
Power Poster
Posts: 7825
Joined: Wed Apr 23, 2008 7:53 am
Contact:

Re: Conditional issue

Post by Rolf »

{$news_there} should have some content when no articles present.
Check if the content of {news} is empty.
- + - + - + - + - + - + -
LATEST TUTORIAL AT CMS CAN BE SIMPLE:
Migrating Company Directory module to LISE
- + - + - + - + - + - + -
Image
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3497
Joined: Mon Nov 28, 2011 9:29 am

Re: Conditional issue

Post by velden »

I think it's somewhat strange to check for one condition ({news}) and if not empty show something else ({news category="*Society*" detailpage="society" summarytemplate="cw-news-no-category-tag" articleid="-1"}).

It could be that {news} is not empty but the {news category="*Society*" detailpage="society" summarytemplate="cw-news-no-category-tag" articleid="-1"} is.

Why not make it a little more efficient:

Code: Select all

{capture assign="news_there"}{news category="*Society*" detailpage="society" summarytemplate="cw-news-no-category-tag" articleid="-1"}{/capture}
<h4>{breadcrumbs root="home" starttext="You are visiting "}</h4>
{if $news_there}
  {$news_there}
{else}
<h2>No article on {title} section</h2>
<p>We are sorry there is no published articles in this section. Please look at other pages at this time and come back again.</p>
{/if}
Then you have only one call to the news module AND you're checking for the condition you really want to know about.

Further, for debugging purposes you could just print the content of the variable in comments. So you see why it triggers a true or false:

Code: Select all

<!-- $news_there: '{$news_there}' -->
luya
Forum Members
Forum Members
Posts: 91
Joined: Wed Jan 23, 2013 1:34 am

Re: Conditional issue

Post by luya »

{news} was not empty buy in this case {news category=*Society*} is according to the comment velden provided on
http://cwmag.ca/stg/en/society.html
The conditional statement should return the message but it seems to contain empty space inside that {news category=*Society*}. Any pointer?
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1968
Joined: Mon Jan 29, 2007 4:47 pm

Re: Conditional issue

Post by Jo Morg »

luya wrote:{news} was not empty buy in this case {news category=*Society*} is according to the comment velden provided on
http://cwmag.ca/stg/en/society.html
The conditional statement should return the message but it seems to contain empty space inside that {news category=*Society*}. Any pointer?
News Help wrote:(...)(optional) category="category" - Used in the summary view to display only items for the specified categories. Use * after the name to show children. Multiple categories can be used if separated with a comma. Leaving empty, will show all categories. This parameter also works for the frontend submit action, however only a single category name is supported. (...)
I believe the name of the category is in conflict with this.
"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 Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
User avatar
Rolf
Power Poster
Power Poster
Posts: 7825
Joined: Wed Apr 23, 2008 7:53 am
Contact:

Re: Conditional issue

Post by Rolf »

Try

Code: Select all

{news category='Society*'}
- + - + - + - + - + - + -
LATEST TUTORIAL AT CMS CAN BE SIMPLE:
Migrating Company Directory module to LISE
- + - + - + - + - + - + -
Image
luya
Forum Members
Forum Members
Posts: 91
Joined: Wed Jan 23, 2013 1:34 am

Re: Conditional issue

Post by luya »

Rolf wrote:Try

Code: Select all

{news category='Society*'}
The result from applying a debug comment

Code: Select all

<!-- $news_there: '{$news_there}' -->
returns

Code: Select all

' --> 
It seems empty and should lead to other condition where {news category="Society*"} has no content yet. You can view on http://cwmag.ca/stg/en/society.html
Jo Morg wrote: I believe the name of the category is in conflict with this.
For your information, category "Society" is a child of "English". "*" before the category name is look at its parents, in my case, "English". I discovered that property, the help guide seems to lack that information.
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1968
Joined: Mon Jan 29, 2007 4:47 pm

Re: Conditional issue

Post by Jo Morg »

luya wrote:For your information, category "Society" is a child of "English". "*" before the category name is look at its parents, in my case, "English". I discovered that property, the help guide seems to lack that information
Maybe but, unless the the author states it specifically, for me it's a bug and I wouldn't count on it working.
luya wrote:The result from applying a debug comment Code:<!-- $news_there: '{$news_there}' -->returnsCode:' --> It seems empty and should lead to other condition where {news category="Society*"}
Check your source HTML: there seems to be some misuse of inline css/smarty:

Code: Select all

<!-- $news_there: '<style type="text/css">.news-summary {/*	border-top: 1px solid #ccc; */margin-top: 1em;width: 100%;}.news-summary .heading {margin-top: 0.6em;font-weight: bold;width: 100%;}.article-thumbnail{display: block;max-width: 10em;height: 10em;background-color: #aaa;[[foreach from=$vendors item='one']][[$one]]transition: all .5s;[[/foreach]]transition: all .5s;}.article-thumbnail:hover{background-color: #888;}.news-article-list {font-family: 'asapregular', "Droid Sans", sans-serif;display: block;vertical-align: top;width: 100%;height: 80%;/*	max-width: 18.5em; */border: 1px solid #ccc;box-shadow: 0px 0px 1px #ccc;background-color: #fff;margin: 0 0.4em 1em 0;padding: 0;overflow: hidden;[[foreach from=$vendors item='one']][[$one]]transition: all .5s;[[/foreach]]transition: all .5s;}.news-article-list:hover,.news-article-list:focus {color: #999;background-color: #FCF0EE;[[foreach from=$vendors item='one']][[$one]]box-shadow: 1px 1px 5px #201c1c;[[/foreach]]box-shadow: 1px 1px 5px #201c1c;}.news-article-list strong.category {position: relative;top: .125em;left: 0;margin: 1em 0.2em;font-family: "League Gothic", sans-serif;font-weight: bold;font-size: 200%;font-variant: small-caps;text-indent: 30%;text-shadow: 0px 0px 1px #201c1c;color: #201c1c;}.news-article-list a {text-decoration: none;color: #5f1300;}.news-article-list a > img {display: inline-block;vertical-align: top;width: 30%;height: 10em;margin: .8em;background-color: #ccc;}.news-article-list div.news-info {display: inline-block;vertical-align: text-top;width: 62%;height: 30%;margin: .8em .8em .8em 0;}.news-article-list div.news-info h2.news-title {font-size: 150%;margin: 0;padding: 0;transition: all .5s;[[foreach from=$vendors item='one']][[$one]]transition: all .5s;[[/foreach]]}.news-article-list a:hover{color: #e8231a;}.news-article-list p {font-size: 90%;text-overflow: ellipsis;}.news-meta {font-size: 80%;}</style><!-- .news-summary wrapper --><article class='news-summary'><!-- h2>Latest articles</h2 --><!-- .news-article-list (wrapping each article) --><section class='news-article-list'><div class="news-info"><header class='news-meta'>Oct 10, 2013<strong> Category:</strong> Société<!--   <strong> Posted by:</strong> racine --></header><h2 class="news-title"><a href='http://cwmag.ca/stg/news/10/82/La-guerre-contre-les-femmes.html' title='La  guerre contre les femmes'>La  guerre contre les femmes</a></h2><p> Une guerre invisible mais une réalité envers les femmes.   <span class='more'><a href="http://cwmag.ca/stg/news/10/82/La-guerre-contre-les-femmes.html">More</a> →</span></p></div></section><!-- .news-article-list //--><!-- news pagination --></article><!-- .news-summary //-->' --> <!-- Page content -->
If your css is inline smarty tags should use {} delimiters instead of [[]] which is only required on css residing on the css database.
"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 Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
luya
Forum Members
Forum Members
Posts: 91
Joined: Wed Jan 23, 2013 1:34 am

Re: Conditional issue

Post by luya »

Jo Morg wrote:Maybe but, unless the the author states it specifically, for me it's a bug and I wouldn't count on it working.
Use like

Code: Select all

{news category="English|Society*"}
instead?
Jo Morg wrote: Check your source HTML: there seems to ub]{}[/b] delimiters instead of [[]] which is only required on css residing on the css database.
inline css is applied for news summary template which now uses {} delimiter for smarty. Unfortunately, the issue about conditional statement remains unresolved for empty category news content .
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1968
Joined: Mon Jan 29, 2007 4:47 pm

Re: Conditional issue

Post by Jo Morg »

luya wrote:inline css is applied for news summary template which now uses {} delimiter for smarty. Unfortunately, the issue about conditional statement remains unresolved for empty category news content .
Which apparently means that whatever is on the news summary template makes it so it will never be empty even if there are no news on that/those categories.
I would do one of two things: either move the conditional check to the news summary template or make sure that this template results empty when there are no news to render. 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 Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
luya
Forum Members
Forum Members
Posts: 91
Joined: Wed Jan 23, 2013 1:34 am

Re: Conditional issue

Post by luya »

Here is code of summary template

Code: Select all

{strip}
{capture assign=submitted_images}{$entry->file_location}/{$entry->fieldsbyname.Images->value}{/capture}

<style type="text/css">
.news-summary {
	margin-top: 1em;
	width: 100%;
}
	.news-summary .heading {
		margin-top: 0.6em;
		font-weight: bold;
		width: 100%;
	}
		.article-thumbnail{
			display: block;
			max-width: 10em;
			height: 10em;
			background-color: #aaa;
			{foreach from=$vendors item='one'}
        		{$one}transition: all .5s;
			{/foreach}
			transition: all .5s;
		}
		.article-thumbnail:hover{
			background-color: #888;	
		}

.news-article-list {
	display: block;
	vertical-align: top;
	width: 100%;
	height: 80%;
	border: 1px solid #ccc;
	box-shadow: 0px 0px 1px #ccc;
	background-color: #fff;
	margin: 0 0.4em 1em 0;
	padding: 0;
	overflow: hidden; 
	{foreach from=$vendors item='one'}
        {$one}transition: all .5s;
	{/foreach}
	transition: all .5s;
}

.news-article-list:hover,
.news-article-list:focus {
	color: #999;
	background-color: #FCF0EE;
	{foreach from=$vendors item='one'}
        {$one}box-shadow: 1px 1px 5px #201c1c;
	{/foreach}
   box-shadow: 1px 1px 5px #201c1c;
}
.news-article-list strong.category {
	position: relative;
	top: .125em;
	left: 0;
	margin: 1em 0.2em;
	font-family: "League Gothic", sans-serif;
	font-weight: bold;
	font-size: 200%;
	font-variant: small-caps;
	text-indent: 30%;
        text-shadow: 0px 0px 1px #201c1c;
	color: #201c1c;
} 

.news-article-list a {
	text-decoration: none;
	color: #5f1300;	
}
.news-article-list a > img {
	display: inline-block;
	vertical-align: top;
	width: 30%;
	height: 10em;
	margin: .8em;
	background-color: #ccc;
}

.news-article-list div.news-info {
	display: inline-block;
	vertical-align: text-top;
	width: 62%;
	height: 30%;
	margin: .8em .8em .8em 0;
}

.news-article-list div.news-info h2.news-title {
	font-size: 150%;
	margin: 0;
	padding: 0;
	transition: all .5s;
	{foreach from=$vendors item='one'}
        {$one}transition: all .5s;
	{/foreach}
}
.news-article-list a:hover{
	color: #e8231a;	
}

.news-article-list p {
	font-size: 90%;
        text-overflow: ellipsis;
}
.news-meta {
	font-size: 80%;
}

</style>

<!-- .news-summary wrapper -->
<article class='news-summary'>
    {foreach from=$items item='entry'}
    <!-- .news-article-list (wrapping each article) -->
    <section class='news-article-list'>
        {if $entry->fieldsbyname.Images->value != ''}
        	 <a href='{$entry->moreurl}' title='{$entry->title|cms_escape:htmlall}'>
          {CGSmartImage filter_croptofit="200,200,c" noembed='0' quality='85' src="{$entry->file_location}/{$entry->fieldsbyname.Images->value}" alt="{$entry->title}"}
          </a>
        {/if}
     <div class="news-info">
     <header class='news-meta'>
    	{if $entry->postdate}
        {$entry->postdate|cms_date_format}
    	{/if}
    	{if $entry->category}
        <strong> {$category_label}</strong> {$entry->category}
    	{/if}
    	</header>
        <h2 class="news-title"><a href='{$entry->moreurl}' title='{$entry->title|cms_escape:htmlall}'>
        		{$entry->title|cms_escape}</a></h2>
    
        
    {if $entry->summary}
          <p>{eval var=$entry->summary|strip_tags} <span class='more'>{$entry->morelink} →</span></p>
    {else if $entry->content}
        <p>{eval var=$entry->content|strip_tags}</p>
    {/if}
    
    </div>
    </section>
    
    <!-- .news-article-list //-->
    {/foreach}
        <!-- news pagination -->
        {if $pagecount > 1}
        <span class='paginate'>
            {if $pagenumber > 1}
                {$firstpage} {$prevpage}
            {/if}
                {$pagetext} {$pagenumber} {$oftext} {$pagecount}
            {if $pagenumber < $pagecount}
                {$nextpage} {$lastpage}
            {/if}
        </span>
        {/if}
</article>
<!-- .news-summary //-->

Not sure what causes  the problem.
{/strip}
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3497
Joined: Mon Nov 28, 2011 9:29 am

Re: Conditional issue

Post by velden »

Without debugging the whole template it's obvious that regardless of whether there are items, there will be a lot of output:

everything before {foreach from=$items item='entry'} and after the closing {/foreach} tag.

So you could enclose the whole template in a {if} statements that first checks if $items is empty or not.
User avatar
Jo Morg
Dev Team Member
Dev Team Member
Posts: 1968
Joined: Mon Jan 29, 2007 4:47 pm

Re: Conditional issue

Post by Jo Morg »

IIRC you can wrap the whole template code inside a conditional:

Code: Select all

{if $count>0}
{* the  rest of your template *}
{/if}
It used to work, I'm just not sure {$count} is still available on summary templates...
"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 Condut | CMSMS Docs | Help Support CMSMS
My developer Page on the Forge
GeekMoot 2015 in Ghent, Belgium: I was there!
GeekMoot 2016 in Leicester, UK: I was there!
DevMoot 2023 in Cynwyd, Wales: I was there!
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12711
Joined: Thu Mar 09, 2006 5:32 am

Re: Conditional issue

Post by Dr.CSS »

I would take all the style calls out of the template and put them in a style sheet, then I would check 'if empty' using...

{capture assign='test'}{content block='newsblock'}{/capture}
{if !empty($test)}
<div class="content">
{$test}
</div>{/if}

This '!empty' means if it is not empty...
luya
Forum Members
Forum Members
Posts: 91
Joined: Wed Jan 23, 2013 1:34 am

Re: Conditional issue

Post by luya »

CSS is related to external stylesheet. Here is the modified news summary template.

Code: Select all

{strip}
{capture assign=submitted_images}{$entry->file_location}/{$entry->fieldsbyname.Images->value}{/capture}

<!-- .news-summary wrapper -->
<article class='news-summary'>
{if $count>0}
    {foreach from=$items item='entry'}
    <!-- .news-article-list (wrapping each article) -->
    <section class='news-article-list'>
        {if $entry->fieldsbyname.Images->value != ''}
            <a href='{$entry->moreurl}' title='{$entry->title|cms_escape:htmlall}'>
          {CGSmartImage filter_croptofit="200,200,c" noembed='0' quality='85' src="{$entry->file_location}/{$entry->fieldsbyname.Images->value}" alt="{$entry->title}"}
          </a>
        {/if}
     <div class="news-info">
     <header class='news-meta'>
       {if $entry->postdate}
        {$entry->postdate|cms_date_format}
       {/if}
       {if $entry->category}
        <strong> {$category_label}</strong> {$entry->category}
       {/if}
       </header>
        <h2 class="news-title"><a href='{$entry->moreurl}' title='{$entry->title|cms_escape:htmlall}'>
              {$entry->title|cms_escape}</a></h2>
   
       
    {if $entry->summary}
          <p>{eval var=$entry->summary|strip_tags} <span class='more'>{$entry->morelink} →</span></p>
    {else if $entry->content}
        <p>{eval var=$entry->content|strip_tags}</p>
    {/if}
   
    </div>
    </section>
   
    <!-- .news-article-list //-->
    {/foreach}
        <!-- news pagination -->
        {if $pagecount > 1}
        <span class='paginate'>
            {if $pagenumber > 1}
                {$firstpage} {$prevpage}
            {/if}
                {$pagetext} {$pagenumber} {$oftext} {$pagecount}
            {if $pagenumber < $pagecount}
                {$nextpage} {$lastpage}
            {/if}
        </span>
        {/if}
{else}
<h2>No article on {title} section</h2>
<p>We are sorry there is no published acticles in this section. Please look at other pages at this time and come back again.</p>
{/if}
</article>
<!-- .news-summary //-->
{/strip}
The given condition works with available content but still refuses to return the posted message where is none. :(
Locked

Return to “Layout and Design (CSS & HTML)”