So I want to add videos to my page but unsure how to… I’ve sort of done it but its not the way I want to do it… So within user (or user/pages) I would create a video folder. This was would have subfolders containing 1-5 videos each.
So within \user hemes\hofb emplates\modular I have created a video.html.twig when I use the example within the learn section for videos its working fine {{ page.media[‘test.mp4’].resize(400, 200).html() }}
Within \user\pages\09.videos\artist-videos est-video-1_video I have my test.mp4 video and I have the file video.md which doesn’t have much in it. video.md doesn’t contain the markdown to display the video. When I view this page the page gets rendered and the video displays… So my first issue is that within the twig the video is hard coded to a specific name and I dont want all my videos in different directorys with the same name.
In the twig I tried {{ page.media.videos.resize(400, 200).html() }} | {{ page.media.video.resize(400, 200).html() }} | {{ page.media.video.html() }} {{ page.media.videos.html() }} and within video.md I had the markdown for outputting the video. Page rendered but no video displayed.
So I changed the twig to {{ dump(page.media.videos) }} refreshed the page no video appears but within the debugger I can see in the messages section an aray test.mp4 as below.
Kinda hard to read your message when you don’t use any markdown tags to highlight code If you click the question mark (?) in the forum input box you will get some help on how to use code and codeblocks. Makes it much easier to read code and make sense of it
Anyway, couple of things I noticed. First you have a _video folder. Having an _ at the start of the folder signifies to Grav this is a modular folder, meaning its part of a modular page. The downside of this is that because it’s part of another page, it’s not actually routable directly. This could be an issue if you plan on reaching videos of this page from another page.
Second, the main issue is that you have to understand how page media works. It works for videos, the same way it works for images, just with a more limited set of functionality (can’t crop, add filters, etc). So make sure you read the docs on Media handling so you have a good grasp of it.
What this means is that page.media.vide os returns an array of all the videos. There’s a shortcut that enables you to simply type page.media['myvideo.mov'] that will try to find the file in the arrays it knows about, but that’s only when you know the specific file name. Normally if you don’t know the file, or don’t know the number of files, you would loop over the array of videos, and output them:
{% for video in page.media.videos %}
{{ video.resize(300,300) }}
{% endfor %}
You can use metafiles to store extra information about each video if you wish.
hmmm, yeah as the skeleton had all pages as mod_alt thats what all my pages are based off, having no real understanding of code just made it easier to use the already existing file structure and deleting and renaming parts to fit my needs. I could do a cleanup and try getting everything working as default.md as many of these pages only have one part to it and not multiple.
Under /user/pages/videos/ I would have 50 folders like artist-test-1, artist-test-2 etc. Each one of these folders could have between 1-5 videos. I however plan on only showing one video per page.
On my page i.e. 09.videos/artist-videos/test-video-1 within the .md I would have the below.
I know the path of my video and I know the name of my video and with the built in media capability’s of Grav I thought something like that would of worked out of the box but it doesn’t (?) unless I am mis-understanding something here…
Within http://learn.getgrav.org/content/media all the examples point to hard coded paths. When I add the be low to the twig the video works on the page.
Once again thanks for your help. Your support has been awesome hopefully others will find this useful too.
I modified the above slightly to make song a variable too as it changes per video. Only took me an hour and 20 page breaking errors lol but got their in the end
Hi, awesome that worked after changing pages.find to page.find as per below. The dumps showed null so helped in telling me it could not find the videos folder.