Magento Add Color Picer In Admin Conifuration Page

本文指导您如何仅用几行XML代码在Magento模块的管理员配置页面中添加颜色选择器,简化了通常看起来复杂的任务。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Download JS Extension from here: 

http://jscolor.com/

 

Sometimes you may want to add color picker in the admin configuration page of your Magento module or extension. You may think this as a big task but believe me this is as simple as anything. Few lines of XML code will do it for you. Here are the exact steps to do this.

1. In adminhtml/default/default/layout directory, create the layout XML file for your module. Lets name it as picker.xml. Write following content in picker.xml: 

<?xml version="1.0"?>
<layout version="0.1.1">
 <adminhtml_system_config_edit>
  <reference name="head">
   <action method="addJs"><file>jscolor/jscolor.js</file></action>
  </reference>
 </adminhtml_system_config_edit>
</layout>

 2. Declare the layout file in your module's config.xml as: 

<config>
...
 <adminhtml>
  <layout>
   <updates>
    <basket>
     <file>picker.xml</file>
    </basket>
   </updates>
  </layout>
 </adminhtml>
...
</config>

 3. In your module's system.xml, add the color picker field as:

<config>
...
 <sections>
   <myconfig module="picker" translate="label">
   ...
   <groups>
    <my_group translate="label">
     ...
      <my_color>
       <label>Background Color</label>
       <frontend_type>text</frontend_type>
       <validate>color</validate> <!-- This is important -->
       <sort_order>1</sort_order>
       <show_in_default>1</show_in_default>
       <show_in_website>1</show_in_website>
       <show_in_store>1</show_in_store>
       <comment>Specify the background color.</comment>
      </my_color>
    <my_group>
   </groups>
   <myconfig>
 </sections>
...
</config>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值