Can't echo video file


#1

Hi
I can’t echo the url of my video file correctly from a simple select field. (I’m using the fieldtoggle plugin but I don’t think this doesn’t change anything.)

<?php foreach($page->children()->visible() as $project): ?>
<?php if($project->type() == "videos"): ?>
<?php $video = $project->video()->toFile();?>
<?php echo $video->url() ?>

The URL is echoing without subfolders, I just get the root of the project like http://myswebsite.com/

The blueprint is pretty simple :

  type:
    label:       Projet images ou vidéo
    type:        fieldtoggle
    options:
      images:       "Images"
      videos:        "Vidéos"
    show:
      videos:       vignette video
    hide:
      images:        vignette video
  vignette:
    label:       vidéo vignette (MP4)
    type: select
    options: videos
    width: 1/2
  video:
    label:       vidéo vignette (MP4)
    type: select
    options: videos
    width: 1/2

When I dump the $project I get

[fields] => Array
(
[prevnext] =>
[title] => Test
[client] => Client
[annee] => 2018
[mode] => true
[type] => videos
[vignette] => vignette_air.mp4
[video] => vignette_air.mp4
)


#2

Two problems:

  • your fieldname; video() is a Kirby native function. Solution: Either rename your field or use $project->content()->video() to fetch the value
  • missing if statement, use if($video = $project->videofieldname()->toFile():

#3

Arg, thank you very much, sometimes even the dumbest thing is in front of our eyes…