Page 1 of 2
[Solved] Conditional issue
Posted: Sat Oct 26, 2013 7:55 am
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?
Re: Conditional issue
Posted: Sat Oct 26, 2013 8:01 am
by Rolf
{$news_there} should have some content when no articles present.
Check if the content of {news} is empty.
Re: Conditional issue
Posted: Sat Oct 26, 2013 10:24 am
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}' -->
Re: Conditional issue
Posted: Sat Oct 26, 2013 5:47 pm
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?
Re: Conditional issue
Posted: Sun Oct 27, 2013 2:33 pm
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.
Re: Conditional issue
Posted: Sun Oct 27, 2013 2:41 pm
by Rolf
Re: Conditional issue
Posted: Mon Oct 28, 2013 3:32 am
by luya
The result from applying a debug comment
Code: Select all
<!-- $news_there: '{$news_there}' -->
returns
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.
Re: Conditional issue
Posted: Mon Oct 28, 2013 4:00 am
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.
Re: Conditional issue
Posted: Mon Oct 28, 2013 4:35 am
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 .
Re: Conditional issue
Posted: Mon Oct 28, 2013 4:53 am
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.
Re: Conditional issue
Posted: Mon Oct 28, 2013 10:25 am
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}
Re: Conditional issue
Posted: Mon Oct 28, 2013 10:43 am
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.
Re: Conditional issue
Posted: Mon Oct 28, 2013 11:30 am
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...
Re: Conditional issue
Posted: Mon Oct 28, 2013 7:34 pm
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...
Re: Conditional issue
Posted: Tue Oct 29, 2013 12:35 am
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.
