Invision Community 4: SEO, prepare for v5 and dormant account notifications Matt November 11, 2024Nov 11
Posted August 15, 20159 yr 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?
August 15, 20159 yr {{if $record->customFieldDisplayByKey('thekey', 'display')}} {$record->customFieldDisplayByKey('thekey', 'display')|raw} {{endif}}
August 15, 20159 yr Author {{if $record->customFieldDisplayByKey('thekey', 'display')}} {$record->customFieldDisplayByKey('thekey', 'display')|raw} {{endif}} Many thanks Ralf!
August 15, 20159 yr Author {{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')) }}
Archived
This topic is now archived and is closed to further replies.