Magento 根据后端模块设置加载自定义JS文件
仅当模块后端设置中的属性(“是/否”)设置为“是”时,我才想向模块添加自定义JS文件 到目前为止,我在module config.xml中引用了layout.xml文件,如下所示:Magento 根据后端模块设置加载自定义JS文件,magento,Magento,仅当模块后端设置中的属性(“是/否”)设置为“是”时,我才想向模块添加自定义JS文件 到目前为止,我在module config.xml中引用了layout.xml文件,如下所示: <frontend> <layout> <updates> <modulename> <file>modulename.xml</file>
<frontend>
<layout>
<updates>
<modulename>
<file>modulename.xml</file>
</modulename>
</updates>
</layout>
</frontend>
modulename.xml
layout.xml按预期加载.js文件。如果可能的话,我想添加一个类似于system.xml文件中的依赖项:
<sortby translate="label">
<label>Sort by:</label>
<frontend_type>select</frontend_type>
<sort_order>40</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<source_model>path/to_settings</source_model>
<depends><sortby>1</sortby></depends>
</sortby>
排序方式:
选择
40
1.
1.
1.
路径/到\u设置
1.
无论如何,如何根据后端设置字段的值加载自定义JS文件?您可以添加如下内容:
<reference name="head">
<block ifconfig="path_to_setting" type="your_block_type" name="some_name">
<action method="addJs"><script>path_of_file.js</script></action>
</block>
</reference>
_file.js的路径_
用你的价值观来取代这些东西
ifconfig属性值为true,它将加载您的JS文件。您可以添加如下内容:
<reference name="head">
<block ifconfig="path_to_setting" type="your_block_type" name="some_name">
<action method="addJs"><script>path_of_file.js</script></action>
</block>
</reference>
_file.js的路径_
用你的价值观来取代这些东西
ifconfig属性值为true,它将加载JS文件