Creating a Dynamic Content plugin for Vimeo and Youtube using Regex
You have probably made a dynamic content plugin before in your projects and using either youtube or another service. But in this case I am using both vimeo and youtube. So the big thing about this is not creating a dynamic content plugin for video but for two using a nice regex. When I got this in my project I thougt it was easy and it should be but the tricky part was greating a nice Regex that could decide if it was a video from youtube or vimeo.
So what have i done.. well as I am not a real geek as Ted Nyberg, http://tedgustaf.com/en/blog/2011/4/creating-dynamic-content-in-episerver-cms-6-r2/, so I choose the simple way in life and use the EPiServer VS integration stuff.
Rightclick on a folder i VS and add a new EPiServer Dynamic Content like this:
When that is done you have a nice usercontrol for dynamic content. Looking something like this in front-end:
and like this in back-end:
so now it is time to add our custom code.
Add properties on the Dynamic Content settings
In this plugin I only need one property and that is the string were I enter the url to the video.
To handle to diffrent videorurl we need two diffrent Regex. One for Vimeo and one for Youtube.
These regex will handle, as far as i can tell, all diffrent links at the moment They will be used too decide if we should use the iframe for youtube or for vimeo.
Creating the Player()
Here I create diffrent iframes depending on the success of the Regex.
Now lets update the front-end so that we actually will render the player.
Finally edit a page and insert your new dynaminc content. Copy/paste the url from either vimeo or youtube into the VideoUrl and the result will look something like this..
Thats it! Hopefully this will help someone…