0

I'm trying to add a custom CSS file when a Magento action is loaded.

My layout page is as follows :

<layout version="0.1.0">

<helloworld_index_index>
  <reference name="head">

        <action method="addCss">
            <stylesheet>css/custom.css</stylesheet>
        </action>
    </reference>
       <reference name="root">
         <block type="page/html" name="root"  output ="toHtml" template = "mypage.phtml"/>

     </reference>

</helloworld_index_index>
</layout>

The content of mypage.phtml displays without a problem but the CSS is not loaded. The path to my css is :

skin\frontend\base\default\css\custom.css

2
  • Check these links magento.stackexchange.com/questions/61334/… OR simicart.com/blog/magento-css Commented Nov 22, 2018 at 6:44
  • Thank you. Adding the css to page.xml does work but i want it for specific modules and pages only like when i call action helloworld/index/index the css file is not loaded when i check chrome dev tools. Commented Nov 22, 2018 at 8:29

2 Answers 2

0

The path to the stylesheet directory will depend on what you have set in System=>Configuration=>General=>Design=>Themes=>Skin (Images / CSS) so depending on what you have set there, it will look in that directory for the CSS file.

You can easily find out where Magento is looking for that stylesheet by going on the frontend of the website and looking at the console log, there should be a 404 for the custom.css file.

Always make sure to flush your cache when you make layout changes

5
  • The skin config is empty ,i'm using default magento install with sample data. And i see not 404 error for the css file in the console. Commented Nov 21, 2018 at 17:29
  • did you flush/clear the cache? Commented Nov 21, 2018 at 17:30
  • Use i deleted the var cache folder and i have already disabled all cache Commented Nov 21, 2018 at 17:32
  • did you try <action method="addItem"><type>skin_css</type><name>css/custom.css</name></action> Commented Nov 21, 2018 at 17:39
  • It didn't work. Same result :/ Commented Nov 21, 2018 at 17:48
0

you can try below code this code work for me

<reference name="head">
    <action method="addItem">
        <type>skin_css</type>
        <name>css/custom.css</name>
    </action>
</reference>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.