[LISE] check if field definition content empty

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Locked
10010110
Translator
Translator
Posts: 217
Joined: Tue Jan 22, 2008 9:57 am

[LISE] check if field definition content empty

Post by 10010110 »

OK, I’m displaying entries by category with LISE like this:

Code: Select all

<!-- category template -->
{if $categories > 0}
<section>
	<h2>Title</h2>
	<div class="categories">
	{foreach $categories as $cat}
		{$level = $cat->depth}
		{$prevlevel = $cat->prevdepth}
		{* close section *}
		{if $level === 1 && $prevlevel === 2}
		</section>
		{/if}
		{if $cat->fielddefs}
			{$item = $cat}
			{$fielddef = $cat->fielddefs}
		<a href="{$item->url}">{CGSmartImage src="{$fielddef.image->GetImagePath(true)}/{$fielddef.image.value}" alt="{$item->title}" title="{$item->title}" filter_resize='h,100'}</a>
		{else if $cat->items|count > 0}
		<section class="category-{$cat->alias}">
			<h3>{$cat->name}</h3>
		{/if}
	{/foreach}
	{* close last section *}
		</section>
	</div>
</section>
{/if}
<!-- end category template -->
I also have a field definition called “description” which is a WYSIWYG field. I’m now trying to check whether that field has any value and display the results differently depending on the condition, like in this example:

Code: Select all

{$fielddef = $cat->fielddefs}
{if !empty($fielddef.description)}
	has description
{/if}
But whatever I do, it never seems to be empty, even if there is no content. Is there any special trick to this?
User avatar
DIGI3
Dev Team Member
Dev Team Member
Posts: 1629
Joined: Wed Feb 25, 2009 4:25 am
Location: Victoria, BC

Re: [LISE] check if field definition content empty

Post by DIGI3 »

Try changing

Code: Select all

{$fielddef = $cat->fielddefs}
{if !empty($fielddef.description)}
   has description
{/if}
to

Code: Select all

{$fielddef = $cat->fielddefs}
{if !empty($fielddef.description->value)}
   has description
{/if}
I haven't tested in a category view, but in a summary/detail view you need to include the ->value part to test for it, e.g. {$item->fielddefs.description->value}
Not getting the answer you need? CMSMS support options
10010110
Translator
Translator
Posts: 217
Joined: Tue Jan 22, 2008 9:57 am

Re: [LISE] check if field definition content empty

Post by 10010110 »

Hm, it doesn’t seem to work. Now it always sees the value as empty. Simplified code:

Code: Select all

{foreach $categories as $cat}
	{if $cat->fielddefs}
		{$cat->fielddefs.description->value}
		{if empty($cat->fielddefs.description->value)}
		empty
		{else}
		full
		{/if}
	{/if}
{/foreach}
If I put some text into the description field, it will output the text from {$cat->fielddefs.description->value} but still print “empty”. ???
User avatar
DIGI3
Dev Team Member
Dev Team Member
Posts: 1629
Joined: Wed Feb 25, 2009 4:25 am
Location: Victoria, BC

Re: [LISE] check if field definition content empty

Post by DIGI3 »

maybe try just {if $cat->fielddefs.description->value}full{else}empty{/if}

or you could test the length or something. It does seem off, but perhaps something unique to category templates.
Not getting the answer you need? CMSMS support options
10010110
Translator
Translator
Posts: 217
Joined: Tue Jan 22, 2008 9:57 am

Re: [LISE] check if field definition content empty

Post by 10010110 »

Wow, thanks for the super quick reply. :) Indeed, just {if $cat->fielddefs.description->value} seems to do the trick.
Locked

Return to “Modules/Add-Ons”