The Mighty Blog

Jan21

Written by:Will
1/21/2009  RssIcon

When we talk about widgets, it is easy to forget about widgets we use everyday. Once of those is the YouTube widget, but now DNN makes it easier than ever to embed a YouTube video into your website.

Widgets have been called any things, but the main thing to remember is that a widget is just content that is imported from another place.  The "place" could be on your own site, or in the case of some videos, YouTube.  That is what we will focus on this time.

DotNetNuke 5 has an embed widget that makes it easy to embed many common objects such as: YouTube videos, Google Analytics code, Flash objects, Flickr, WidgetBox, and Disqus.  I was very surprised to not see Silverlight in the list of default embed types.  I was only a little surprised to not see Quantcast as well.

Before you choose to embed a YouTube video, you need to first find the video id number.  This is easily found on the video page on YouTube.

YouTube Website Screen Shot

Every video has the id in the URL provided.  Here is the URL from the previous screen shot.  You will quickly notice the video id in the querystring.  Keep that id number for later (_y36fG2Oba0).

http://www.youtube.com/watch?v=_y36fG2Oba0

Now, you need to login to the DNN website were you want the video to be embeded into.  Add a Text/HTML Module to any page, or choose an existing module.  We will want to click "Edit Text" as if we were going to make any other textual change.  You will then want to make sure you are working with the source, but I prefer to use the normal textbox view.

Edit Text - Embed Widget Snippet for YouTube

Notice in the screen shot that I selected the HTML view option.  I do this because if you leave this at the default of Text, DNN will replace all line breaks with BR tags.  When you are writing HTML, this will have very ill side effects.

Now, we need to include a small snippet of code for the embed widget.  This widget code similar to any other DNN widget.  Here is the example of the code I am using for this blog entry.

<object id="EmbedYouTube" codetype="dotnetnuke/client" codebase="EmbedWidget" declare="declare">
    <param name="Type" value="YouTube" />
    <param name="src" value="_y36fG2Oba0" />
</object>

Notice that the codebase value is "EmbedWidget", and the two parameters.  The first parameter is required anytime you use the EmbedWidget.  It defines the type of widget that will be embeded into the page.  In this case, the value is "YouTube" to specify that we are embedding a YouTube video.  Finally, we need to tell the EmbedWidget which video we want to embed.  This is where the "Src" parameter comes into play.

Once the parameters are filled, update the text module, and view the page.  You should see your video ready to play.

Embed Widget Importing a YouTube Video

That's it!  Incredibly simple, right? 

Here is the previous code snippet with comments added to it so that it better explains how the parameters are used.

<object id="EmbedYouTube" codetype="dotnetnuke/client" codebase="EmbedWidget" declare="declare">
    <!-- (required) Type: The name of the Embed widget to use & determines the name of folder/file to look for it at -->
    <!-- DNN:       ~/Resources/Widgets/DNN/EmbedWidgetResources/[Type]/[Type].snippet.htm -->
    <!-- Non-DNN:   ~/Resources/Widgets/User/[Publisher]/EmbedWidgetResources/[Type]/[Type].snippet.htm -->
    <param name="Type" value="YouTube" />
    <!-- (optional) MultiValueDelimiter: Use if you want to specify a new delimeter other than a semi-colon -->
    <param name="MultiValueDelimiter" value=";" />
    <!-- (optional) Publisher: Only necessary for non-DNN Embed snippets -->
    <!-- When used, this determines the folder path to look for the snippets in: -->
    <!-- ~/Resources/Widgets/User/[Publisher]/EmbedWidgetResources/[Type]/[Type].snippet.htm -->
    <!--param name="Publisher" value="" /-->
    <!-- Parameters Specific to YouTube Widget -->
    <param name="src" value="_y36fG2Oba0" />
</object>

Technorati Tags: , , , , ,

Copyright ©2009 Will Strohl

10 comment(s) so far...


Gravatar

I followed your instructions and got the error: "Safarai can't find the Internet plug-in. The page has content of MIME type "YouTube". Because you don't have a plug-in installed for this MIME type, this content can't be displayed. Can you help?

By Greg on   9/12/2009
Gravatar

Unfortunately, I have not tried using any of the widgets or test anything on Safari - due to its market share and lack of rendering features.

Also, remember to remove the HTML comments from my example. Those are just to help you.

By Will on   9/12/2009
Gravatar

can you specify a size for the youtube video?

By shaun on   12/21/2009
Gravatar

@Shaun: Yes. You can. In fact, if you check the snippet HTML template, you can see that there are several optional parameters that you are able to assign. Find the template here:

~\Resources\Widgets\DNN\EmbedWidgetResources\YouTube\youtube.snippet.htm

In that template, you'll see that you can also define the width, height, fullscreen, and scriptaccess parameters. You'd specify each just using another parameter HTML tag. Here's an example using width:

[param name="width" value="425" /]

(pretend the square brackets are actually the HTML brackets)

By Will on   12/21/2009
Gravatar

Hi, can we embed videos from other sources such as blip.tv, myspace.com etc?

Thanks

By navnish on   2/12/2010
Gravatar

@Navnush: That's the beauty of the Embed Widget. It doesn't matter what you want to embed, you just create an embed folder of your own, copy the pattern that DNN uses, and you can embed nearly anything.

By Will on   2/12/2010
Gravatar

Has anyone tried to add support for Silverlight apps this way?

By Jeff on   7/2/2010
Gravatar

I am sure someone has, but I don't know of anyone off-hand.

By Will on   7/2/2010
Gravatar

Hi
I'm a novice to DotNetNuke. I've embedded a youtube video recently to the bottom of my content pane. Its position is all right in Firefox but in IE it re-sizes my content pane and makes my right pane move to the bottom of my page. Can you please help me out with this issue? I appreciate your help in advance.

By Elnaz on   7/15/2010
Gravatar

If you are having display issues in IE vs. Firefox, then you need to revisit the HTML and CSS that comprise your skins. containers, and that wrap the widget itself. One or more of those areas needs a CSS/HTML fix to prevent the problem you're experiencing.

By Will on   7/15/2010

Your name:
Gravatar Preview
Your email:
(Optional) Email used only to show Gravatar.
Your website:
Comment:
Security Code
CAPTCHA image
Enter the code shown above in the box below
Add Comment   Cancel 
Add to Technorati Favorites
Tweet about my blog
Will Strohl - The Mighty Blog - RSS Feed

Tag Cloud

Sort by:Tag | SizeRSS
camp   community   dnn   dotnetnuke   dotnetnuke®   event   example   free   get   group   integer   jquery   meeting   module   new   odug   orlando   search   session   think  
The opinions expressed here are the personal opinions of Will Strohl and do not necessarily represent the views and opinions of the DotNetNuke Corporation.
© Copyright 2004-2010 by Will Strohl. All rights reserved.Website Skinned By: Ralph Williams  Website Hosted By: Applied Innovations