Home > Magento Tutorials > Creating a YouTube Video Tab

Creating a YouTube Video Tab

Posted on: 22nd Jul 2010 By: Robert Kent 4 Comments

For this tutorial, you will need the modern theme installed.

What we are going to do is to add an attribute to our attribute set where you can embed the youtube video code. This will then display on the front end of the website for your products.

The files you will need to create/edit are:

- app/design/frontend/default(or base)/default/catalog/products/view/youtube.phtml – create

- app/design/frontend/default(or base)/modern/catalog.xml – edit

First of all create your attribute – we’ll make it a textarea and call it youtube. Give it the settings shown in the image. We’ll then add it to our attribute set.

(Note: I was working on a 1.3 version of magento and due to a small bug I needed to use the description tab and  block – it should work for you if you created the new files. )

Secondly you need to paste the following code into your youtube.phtml file.

<?php if ($this->getProduct()->getYou_tube()) { echo "<div>".$this->getProduct()->getYou_tube()."</div>"; } ?>

Lastly all you need to do is set up a new tab in your xml file. Paste in the following code.

<action method="addTab" translate="title" module="catalog"><alias>description</alias><title>Featured Video</title><block>catalog/product_view_description</block><template>catalog/product/view/description.phtml</template></action>

That’s it! Now all you have to do it paste in the embed code from youtube and you can enjoy a nice product video in a tab! Happy days.

4 Responses to “ Creating a YouTube Video Tab ”

  1. M.Keegan
    #1 | 30th August 2010

    Not sure what I’ve done wrong, but I receive the following error:

    Invalid method Mage_Catalog_Block_Product_View::addTab(Array(
    [0] => description
    [1] => Featured Video
    [2] => catalog/product_view_description
    [3] => catalog/product/view/description.phtml
    )
    )

    Any ideas what’s gone wrong?

  2. M.Keegan
    #2 | 30th August 2010

    Managed to solve the problem. To work with Magento 1.4.0.1 the code for the xml file must be:

    youtubeFeatured Videocatalog/product_view_descriptioncatalog/product/view/youtube.phtml

    This should be placed within the “product_view_tabs” block in catalog.xml.

  3. Beauty Indulgence
    #3 | 15th November 2010

    Hi
    this is fanstanstic but will this work in 1.4.1.1

  4. Yashar
    #4 | 18th June 2011

    To get it working on 1.5.1 you need to change the code in catalog.xml to:

    YoutubeFeatured Videocatalog/product_view_descriptioncatalog/product/view/youtube.phtml

Post A Comment

Your comments:
Enclose code snippets within the appropriate tags: [php][/php]   [js][/js]   [xml][/xml]   [css][/css]   [html][/html]
E.g: [php]<?php echo "hello world"; ?>[/php]

Search Blog

Archives

For the record...

Views & opinions in this blog are those of the individual and do not necessarily reflect those of E-commerce Web Design or the Creare Group.