How can I hook on scripts and CSS into <head>?

前端 未结 3 1826
迷失自我
迷失自我 2021-01-01 02:37

The thing with the module I am making is that it kind of generates a javascript snippet, so I cannot use an action to just hook that into the section of the HTML since the

3条回答
  •  忘掉有多难
    2021-01-01 03:08

    The stock head template is

    template/page/html/head.phtml
    

    Copying that file in your own theme would be the simplest way to get some javascript in the head.

    Better though (from a developer point of view), this template includes the following line

    getChildHtml() ?>
    

    The about link prints out all the child blocks of a block. So, adding a child block to the head block would also work.

    
         
             
                 
                     
                        
                            alert("foo");
                        
                        //]]>
                    
                
            
        
    
    

    The above XML uses a simple core/text block to add javascript to every Magento page. Works from local.xml, should work elsewhere. I'm sure better ways to do this should spring to mind (template block, for example)

提交回复
热议问题