This can be tricky, especially trying to get a latest video from a channel to show in Drupal…. I’ve seen several attempts, using several modules, custom modules, you name it… However, it’s actually quite straight forward….
First, get your YouTube RSS Feed code from here: www.jonmoore.co.uk/html-and-css/youtube-rss-feed
Then follow the instructions here: www.jonmoore.co.uk/drupal/handling-rss-feeds-with-drupal-view-module
No extra modules, no custom code, but no video to play either…
In the 2nd link above, ‘Drews’ adds all the fields, however the only one I was interested in was the ‘Aggregator: Link’, which simply produced a full HTML link to the video. This looked something like ‘http://www.youtube.com/watch?v=###########&feature=youtube_gdata’ where ‘###########’ was the YouTube code for the video. Again, All I wanted was a video that would play, so the only thing I was interested in was that 11 digit YouTube code, and this is where the View templates can come in handy….
Go to ‘Theme: Information’ under ‘Advanced’ in Drupal 7, (Drupal 6 is morw obvious)… and you’ll see the different templates used to process each part of the view. My ‘View’ was called ‘Display YouTube RSS Feed’ and therefore I created a file called ‘views-view-field–display-youtube-rss-feed–link.tpl.php’ to override the normal processing. The file is saved in my theme folder, so ‘sites/all/themes/MYTHEMENAME/’ and I actually have a ‘template’ folder in my theme for files like this… but it’s not needed, so it can just go in ‘sites/all/themes/MYTHEMENAME/’….
Inside the file I have the following:
<?php $ytSplit1 = explode("?v=",$output); $ytSplit2 = explode('&',$ytSplit1[1]); $output = $ytSplit2[0]; ?> <iframe width="200" height="122" src="http://www.youtube-nocookie.com/embed/<?php print $output; ?>?feature=youtube_gdata&wmode=transparent&rel=0&modestbranding=1&showinfo=0" frameborder="0" allowfullscreen></iframe>
Just to explain (very simply) what is happening here…
$ytSplit1 = explode("?v=",$output); removes the first part of the link
$ytSplit2 = explode("&",$ytSplit1[1]); removes the last part of the link, so we now only have the 11 digit YouTube code
$output = $ytSplit2[0]; resets $output to the 11 digit YouTube code
Then the <iframe> uses the standard embed code YouTube provides….
OK, not quite, there are a couple of variables in the <iframe> URL I should explain…
width=”200″ height=”122″ fairly straight forward, width and height of the video….
?feature=youtube_gdata came with the YT feed URL, so I added it back in…
&wmode=transparent is a Flash variable, and it’s important to stop z-index issues…
&rel=0 disables the ‘related videos’ that YouTube adds an the end of the video…
&modestbranding=1 not so important here as I’m knocking out the controls in the next bit, but handy if you remove the next bit…
&showinfo=0 removes the controls and title so you only get the ‘start’ button…
Make sure the template file has been uploaded and ‘Clear Caches’ to make sure the ‘View’ scans the templates and picks the new one up…
That’s it… Simple…??!!!??!!