I have my own module in System->Configuration and want to add js and css files for it. Now it is so:
我在System->配置中有自己的模块,我想为它添加js和css文件。现在它是如此:
<layout version="0.1.0">
<default>
<reference name="head">
<action method="addItem"><type>js_css</type><name>prototype/windows/themes/default.css</name></action>
<action method="addCss"><name>mymodule.css</name></action>
</reference>
</default>
</layout>
This way files added to all Admin pages. What to do to add this files just to one page, so write not default, but mymodule_admin or smth like that?
这样,文件就添加到所有的管理页面。如何将这些文件只添加到一个页面,因此写入的不是默认的,而是mymodule_admin或smth之类的?
1 个解决方案
#1
4
By default, you can use the adminhtml_system_config_edit
handle, it would allow you to add your JS / CSS files on the system configuration pages only, as Magento does not provide finer layout handles for those pages.
默认情况下,您可以使用adminhtml_system_config_edit句柄,它只允许您在系统配置页面上添加JS / CSS文件,因为Magento没有为这些页面提供更好的布局句柄。
But if you really need to add your styles to your system configuration form only, then you could either :
但是,如果您确实需要只将样式添加到系统配置表单中,那么您可以:
-
add an event observer on
controller_action_layout_load_before
to add your own handle to the layout when the action isadminhtml_system_config_edit
and whenMage::getSingleton('adminhtml/config_data')->getSection()
is corresponding to the section of your configuration在controller_action_layout_load_before中添加一个事件观察器,当操作是adminhtml_system_config_edit时,在该布局中添加您自己的句柄时,当法师::getSingleton('adminhtml/config_data')->getSection()对应于您的配置部分。
-
add an event observer on
controller_action_layout_render_before_adminhtml_system_config_edit
that would directly add your JS / CSS files to thehead
block, whenMage::getSingleton('adminhtml/config_data')->getSection()
is also corresponding在controller_action_layout_render_before_adminhtml_system_config_edit上添加一个事件观察者,当Mage: getSingleton('adminhtml/config_data')->getSection()时,该事件观察者将直接将JS / CSS文件添加到head块中
#1
4
By default, you can use the adminhtml_system_config_edit
handle, it would allow you to add your JS / CSS files on the system configuration pages only, as Magento does not provide finer layout handles for those pages.
默认情况下,您可以使用adminhtml_system_config_edit句柄,它只允许您在系统配置页面上添加JS / CSS文件,因为Magento没有为这些页面提供更好的布局句柄。
But if you really need to add your styles to your system configuration form only, then you could either :
但是,如果您确实需要只将样式添加到系统配置表单中,那么您可以:
-
add an event observer on
controller_action_layout_load_before
to add your own handle to the layout when the action isadminhtml_system_config_edit
and whenMage::getSingleton('adminhtml/config_data')->getSection()
is corresponding to the section of your configuration在controller_action_layout_load_before中添加一个事件观察器,当操作是adminhtml_system_config_edit时,在该布局中添加您自己的句柄时,当法师::getSingleton('adminhtml/config_data')->getSection()对应于您的配置部分。
-
add an event observer on
controller_action_layout_render_before_adminhtml_system_config_edit
that would directly add your JS / CSS files to thehead
block, whenMage::getSingleton('adminhtml/config_data')->getSection()
is also corresponding在controller_action_layout_render_before_adminhtml_system_config_edit上添加一个事件观察者,当Mage: getSingleton('adminhtml/config_data')->getSection()时,该事件观察者将直接将JS / CSS文件添加到head块中