Search code examples
phpjquerymagentoheaderfancybox

Insert code in header - but only on CMS page (Magento + Fancybox)


I need to insert this code in the header of one CMS page:

<!-- FancyBox Script -->
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<link rel="stylesheet" href="/fancybox/source/jquery.fancybox.css?v=2.1.5" type="text/css" media="screen" />
<script type="text/javascript" src="/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>

First I inserted the code in the header (so it is on all pages on the site), but then the add to cart function didn't work. So I need the code to only appear on a specific CMS page where I need the Fancybox. How can I do that?


Solution

  • Do you need to do this in code? I'd suggest doing this through the ADMIN system. Simply switch to code view and paste it in.

    Alternatively, create a module, and .phtml template file with this content, then add it to the page in the ADMIN using Layout XML updates.

    If you edit the CMS Page you want to include Fancybox on, click on the design tab, and then include the following in the Layout XML Update section:

    <reference name="head">
        <block type="core/text" name="fancyboxcode">
            <action method="setText">
                <text>
                    <![CDATA[
                    <link rel="stylesheet" href="/fancybox/source/jquery.fancybox.css?v=2.1.5" type="text/css" media="screen" />
                    <script type="text/javascript" src="/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
                    ]]>
                </text>
            </action>
        </block>
    </reference>