Adding new css js files to magento’s template

To add new css js files to magento’s template, for example, add the following in the file page.xml which is located in magentoHomeDir\app\design\frontend\default\yourTheme\layout

<layout>
    <default>
        <reference name="head">
            <action method="addItem"><type>skin_css</type><file>css/additional.css</file></action>
        </reference>
    </default>
</layout>

To add a inline javascript files within the head tag
Add the line in the middle below to app/design/frontend/base/default/layout/page.xml, type has to be declared in a module or we can borrow the core/template, name could be anything, if we name it js_hello, we can call it by getChildHtml(“js_hello”);

<block type="page/html_head" name="head" as="head">
...
	<block type="core/template" name="js_hello" template="page/js/hello.phtml"/>
...
</block>

Create the template app/design/frontend/base/default/template/page/js/hello.phtml

<script type="text/javascript">
alert("hello");
</script>

Clear the cache and reload the page.

Search within Codexpedia

Custom Search

Search the entire web

Custom Search