YouTube embed with Plugin not working

hey,

I’m relatively new to kirby and php, so excuse my perhaps simple question for you guys.
I’m trying to use the following plugin:

So I installed it and it works great in the panel. Then I try to show the video. I think I have a misconception there. Here is my code from the blueprint and the frontend:

fields:
youtube_video_01:
Label: Youtube
type: embed
width: 1/2
youtube_video_02:
Label: Youtube
type: embed
width: 1/2

<video src="<?= $page->embed()->url() ?>" autoplay></video>

I get no error or output. I also tried the example:

<?=
if($embed = $page->myfield()->toEmbed()) {
     echo $embed->code()
}
?>

There the following error message appears in debug mode:
ParseError thrown with message “syntax error, unexpected token “if””

Thanks for the help :slight_smile:

You have to remove the short echo tag and rename the field according to your field

Try this

<?php

if($embed = $page->youtube_video_01()->toEmbed()) {
     echo $embed->code()
}
?>

Thanks, for your feedback.

This line worked finde for me:

<?= $page->youtube_video_01()->toEmbed()->code() ?>

Hey i follow your problem, because i ran into some problems with this same plugin but at least i could figure out some porblems so for me its running somehow. Now to the somehow. I have i think a realy basic problem.

I have this snippet

C:\MAMP\htdocs\starterkit-main\site\snippets\video02.php

    <figure>
      <span class="video" style="--w:16;--h:9">
        <?= video($embed->url()) ?>
      </span>
      <?php if ($embed->caption()->isNotEmpty()): ?>
      <figcaption class="video-caption"><?= $embed->title() ?></figcaption>
      <?php endif ?>
    </figure>    

and got a Error
Call to a member function url() on null

This error appears only on pages where i didnt filled out the url field for a video. I tried out to wrap it up with an if clause and isNotEmpty() but somehow kirby is rejecting it too. Perhaps somebody has an idea? Thanks for your help

Assuming that $embed is the same as what someone else posted above

<?php if ($embed): ?>
 <figure>
      <span class="video" style="--w:16;--h:9">
        <?= video($embed->url()) ?>
      </span>
      <?php if ($embed->caption()->isNotEmpty()): ?>
      <figcaption class="video-caption"><?= $embed->title() ?></figcaption>
      <?php endif ?>
    </figure>  
<?php endif ?>

Otherwise it helps if you show how your variable is defined.

Nice that already solved it! Thanks s a lot! Yes $embed is exactly used like above!