0

I need to add into head custom css file, but it should be applied only for admin pages that are inside my extension.

So I don't need this:

<default> 
    <reference name="head">      
      <action method="addItem"><type>skin_css</type><name>company_module/css/styles.css</name></action>
    </reference>
</default>

but I need this:

<adminhtml_section_one_index> 
    <reference name="head">      
      <action method="addItem"><type>skin_css</type><name>company_module/css/styles.css</name></action>
    </reference>
</adminhtml_section_one_index>
<adminhtml_section_one_edit> 
    <reference name="head">      
      <action method="addItem"><type>skin_css</type><name>company_module/css/styles.css</name></action>
    </reference>
</adminhtml_section_one_edit>
...

This is obvisouly not a nice solution because there will be 10+ different controller actions. Is there any way to match the whole controller or module?

0

Step1: Go to skin/adminhtml/default/default and place your file under module/custom.css

Step2: Go to app/design/adminhtml/default/default/layout and create the file module.xml with the following code:

<?xml version="1.0"?>
<layout>
    <default>
        <reference name="head">
            <action method="addCss">
                <name>module/custom.css</name>
            </action>
        </reference>
    </default>
</layout>

Step3: Now connect your xml file to the module in Namespace/Module/etc/config.xml

<config>
...
<adminhtml>
    <layout>
        <updates>
            <namespace_module>
                <file>module.xml</file>
            </namespace_module>
        </updates>
    </layout>
</adminhtml>
...
</config>
1
  • I am not sure if you understand my question properly. I know how to add custom layout and css. But my problem is because I want to use custom css only for sections that are related to my module and not entire admin. <default> will affect entire admin. Other option I have is to use each controller action as section for reference. But this is not good solution because I will need to repeat <reference name="head"> for each controller action. Please read my question again. – JohnyFree Sep 12 '17 at 16:29
0

I found my answer here.

I can not update layout for all controller actions together, but what could be done to minimize repeated code is to use <update handle="handle_name" />.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.