I have used the Embed plugin to create a video section:
<?php if ($page->work_video()->isNotEmpty()): ?>
<div class="video">
<div class="video-container">
<?php if($embed = $page->work_video()->toEmbed()): ?>
<div class="video-wrapper">
<?= video($embed->url()) ?>
</div>
<?php endif ?>
</div>
</div>
<?php endif ?>
and it works perfectly, but when the user puts a video link and for some reason decides don’t embed it anymore and cancel it, the div persists in the front end, in other words, the Embed plugin does not register that the field is empty.
What remains stored in the work_video field when the video link is removed?
The blank container, this is the outer HTML:
<div class="video">
<div class="video-container">
</div>
</div>
But if the field is empty, the div musn’t be rendered, correct?
I asked about the content field i.e. in the text file… Is the text field really empty when the embed url is removed.
Yes, this:
----
Work-video:
input: ""
media: [ ]
----
Ok, so that’s why isEmpty()
doesn’t work with this field type.
So, what does
var_dump($page->work_video()->toEmbed());
give you?
NULL.
It’s strange. The plugin doesn’t erase the value.
In that case, you can do the following instead of checking if the field is empty:
<?php if ($embed = $page->work_video()->toEmbed()): ?>
<div class="video">
<div class="video-container">
<div class="video-wrapper">
<?= video($embed->url()) ?>
</div>
</div>
</div>
<?php endif ?>
1 Like