Invision Community 4: SEO, prepare for v5 and dormant account notifications By Matt Monday at 02:04 PM
sobrenome Posted May 27, 2015 Posted May 27, 2015 I have a database where some records can or cannot have YouTube videos.On the record template, I test the fields that have content to show only the ones that are available.But Pages always adds html to YouTube Type field, even if there is no YouTube URL recorded.How to test it?The code that is not working is:{{if $record->customFieldDisplayByKey('video')}} <span itemprop="video">{$record->customFieldDisplayByKey('video')|raw}</span> {{endif}}I have also tried:{{if $record->customFieldDisplayByKey('video')|raw}} <span itemprop="video">{$record->customFieldDisplayByKey('video')|raw}</span> {{endif}}The field outputs on record display:<div class="ipsEmbeddedVideo" contenteditable="false"><iframe id="ytplayer" type="text/html" width="100%" height="390" src="" frameborder="0"></iframe></div>As you can see, there is no URL.
opentype Posted May 27, 2015 Posted May 27, 2015 Test for the field ID directly. That bypasses the additional styling of the field. {{if $record->field_XX}} <span itemprop="video">{$record->customFieldDisplayByKey('video')|raw}</span> {{endif}}
sobrenome Posted May 27, 2015 Author Posted May 27, 2015 And to get the field ID I have to check the database or there is such info on AdminCP?
Marcher Technologies Posted May 27, 2015 Posted May 27, 2015 Test for the field ID directly. That bypasses the additional styling of the field. {{if $record->field_XX}} <span itemprop="video">{$record->customFieldDisplayByKey('video')|raw}</span> {{endif}} There is absolutely nothing wrong with this statement, I just wanted to point out if you want it to be portable, that is, not needing changed per site using the template, you can do this:{{$FieldsClass = '\\IPS\\cms\\Fields' . \IPS\cms\Databases\Dispatcher::i()->databaseId;}} {{$fieldsByKey = array();}} {{foreach $FieldsClass::data('view', $record->container(), $FieldsClass::FIELD_SKIP_TITLE_CONTENT) as $field}} {{$fieldsByKey[$field->key] = 'field_' . $field->id;}} {{endforeach}} {{if isset($fieldsByKey['video']) && $record->$fieldsByKey['video']}} <span itemprop="video">{$record->customFieldDisplayByKey('video')|raw}</span> {{endif}} And to get the field ID I have to check the database or there is such info on AdminCP?Is in the URL as the 'id' URL parameter when editing the field in the ACP.
Recommended Posts
Archived
This topic is now archived and is closed to further replies.