How to use a single file in 2 different articles


#1

Hi,
I would like to use a same file (video) in two different articles:
The video file is already located in a folder video (with subfolder) and fetched through a kirbytag as follows in its original content folder
(video: xx.mp4 poster: xx.png)
Let’s assume that I want to use it again in a different article with kirbytag.
Is it possible (without copy the same file in the new content folder) and with what kind of syntax for kirbytag ?
Thank you


#2

Yes, you can add the path to the page with the video

(video: video/subpage/xx.mp4 poster: video/subpage/xx.png)

#3

Thank you for the swift answer.
It works well with the video (without poster)
but when I add the poster parameter I got the following error message:
Whoops \ Exception \ ErrorException (E_ERROR) Call to a member function url() on string

with the following highlighted line:
$poster_attr = ($poster) ? ' poster="'. $poster->url() .'"' : '';


#4

The video tag is not a default Kirbytag? Check how the poster URL is created, you might have to adapt that.


#5

Actually, I used a snippet and tag from Jancbeck but I guess it should be out of date.


#6

Well, this line from the tag looks for the poster in the current page:

   if ( $poster = $tag->page()->images()->find($tag->attr('poster'))) {
      $args['poster'] = $poster;
    }

You need to change that.


#7

OK, but frankly, I have no idea on how to do it !
Sorry from a newbie


#8

Try this instead of the lines above:

if ( $poster = $tag->file($tag->attr('poster'))) {
  $args['poster'] = $poster;
}

You’ve been around for awhile :wink:.


#9

Perfect ! it works with this modification