x
 
Create New Page
 View Previous Changes    ( Last updated by slim )

Embedding YouTube movies

I used the following method to embed YouTube videos within a blog post.

First you need to create a custom field in your default field group called ‘youtube’ with properties set to None. Hide the formatting menu.

Secondly, embed the youtube player object within your page template. The object embed code on its own looks like this:

<!---Youtube Link--->

<
object width="320" height="264">
<
param name="movie" value="http://www.youtube.com/v/{youtube}"></param>
<
param name="wmode" value="transparent"></param>
<
p><embed src="http://www.youtube.com/v/{youtube}" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></object>
</
object>

You need a conditional to test if the post has an attached video file. If it hasn’t, the embedded player will be ignored, otherwise the player will appear.

In this example, I have the YouTube object code inside my weblog tag before the {body} content inside a conditional statement:

{exp:weblog:entries weblog="{master_weblog_name}" orderby="date" sort="desc" limit="10"}

<p class="date">  {entry_date format=' %l, %F %d, %Y '} - <a href="{profile_path=member/index}">{author}</a></p>

<
h2 class="title">{title}</h2>

{summary}

<!---Youtube Link--->

{if youtube != ""}
<object width="320" height="264">
<
param name="movie" value="http://www.youtube.com/v/{youtube}"></param>
<
param name="wmode" value="transparent"></param>
<
p><embed src="http://www.youtube.com/v/{youtube}" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></object>
</
object>
{/if}

{body}

When you create a new post you will have a custom field called ‘youtube’. In this box you need to paste the clip’s unique ID only. Ignore the rest of the URL, as it is included in the object code block.

For example:

v5bhVyLux9M

Here is an example of the working code in use.

There is a further refinement here of this method where the embedded object code is a separate template.

Category:Tricks Category:Tips Category:HowTo

Categories: