Jump to content

How to test YouTube Type Field on Databases


sobrenome

Recommended Posts

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.

Link to comment
Share on other sites

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.

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...