MeekelTM Posted August 15, 2015 Posted August 15, 2015 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?
Ralf Herrmann Posted August 15, 2015 Posted August 15, 2015 {{if $record->customFieldDisplayByKey('thekey', 'display')}} {$record->customFieldDisplayByKey('thekey', 'display')|raw} {{endif}}
MeekelTM Posted August 15, 2015 Author Posted August 15, 2015 {{if $record->customFieldDisplayByKey('thekey', 'display')}} {$record->customFieldDisplayByKey('thekey', 'display')|raw} {{endif}} Many thanks Ralf!
MeekelTM Posted August 15, 2015 Author Posted August 15, 2015 {{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)EDITLooks like I got it working by changing the top line to:{{if !empty($record->customFieldDisplayByKey('youtube-feature', 'raw')) }}
Recommended Posts
Archived
This topic is now archived and is closed to further replies.