Jump to content

Check if database field is empty in template


MeekelTM

Recommended Posts

I'm wanting to check if a database field is empty within a template. In this case, it's using a YouTube URL and if it is in an article, I want to change how an article is displayed. I've tried the following but unsure the correct syntax in the templates.

        {{if (!empty($record->customFieldDisplayByKey('youtube-feature', 'raw')|raw)) }}
				<iframe id="ytplayer" type="text/html" width="640" height="390"
  				src="{$record->customFieldDisplayByKey('youtube-feature', 'raw')|raw}"
                frameborder="0"/>
        {{endif}}
        
        {{if count( {$record->customFieldDisplayByKey('youtube-feature', 'raw')|raw} )}}
				<iframe id="ytplayer" type="text/html" width="640" height="390"
  				src="{$record->customFieldDisplayByKey('youtube-feature', 'raw')|raw}"
                frameborder="0"/>
        {{endif}}

Can anyone help?

Link to comment
Share on other sites

{{if  $record->customFieldDisplayByKey('thekey', 'display')}}

  {$record->customFieldDisplayByKey('thekey', 'display')|raw}

{{endif}}

 

Actually, I spoke too soon.

So I'm using the following code for testing:

        {{if $record->customFieldDisplayByKey('youtube-feature', 'display')}}
			{$record->customFieldDisplayByKey('youtube-feature', 'display')|raw}
        {{else}}
            {$record->customFieldDisplayByKey('featured-image', 'display')|raw}
          	{$record->_content|raw}
        {{endif}}

However even if the youtube-feature field is empty in the database entry, it doesn't show the featured image and the content.

I really need the if statement to look for an empty or null field (depending on how the system stores the data I guess)

EDIT

Looks like I got it working by changing the top line to:

{{if !empty($record->customFieldDisplayByKey('youtube-feature', 'raw')) }}

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...