自定义Joomla!的模块/组件参数

Joomla!的灵活结构再次让我省心省事了。虽然Joomla!的菜单导航组件很不错,但是一些不算很通用的功能就需要自己定制,例如为每个栏目设定背景图或者标题图。

我是这样做的:

/administrator/components/com_menus/models/metadata/component.xml

<?xml version=”1.0″ encoding=”utf-8″?>
<metadata>
<state>
<name>Component</name>
<description>Component Parameters</description>
<params>
<param name=”page_title” type=”text” size=”30″ default=”” label=”Page Title” description=”PARAMPAGETITLE” />
<param name=”show_page_title” type=”radio” default=”1″ label=”Show Page Title” description=”SHOW/HIDE THE PAGES TITLE”>
<option value=”0″>No</option>
<option value=”1″>Yes</option>
</param>
<param name=”pageclass_sfx” type=”text” size=”20″ default=”” label=”Page Class Suffix” description=”PARAMPAGECLASSSFX” />
<param name=”@spacer” type=”spacer” default=”” label=”” description=”” />
<param name=”menu_image” type=”imagelist” directory=”/images/stories” hide_default=”1″ default=”” label=”Menu Image” description=”PARAMMENUIMAGE” />
<param name=”bg_image” type=”imagelist” directory=”/images/stories/bg” hide_default=”1″ default=”” label=”Background Image” description=”My background” />
<param name=”@spacer” type=”spacer” default=”” label=”” description=”” />
<param name=”secure” type=”radio” default=”0″ label=”SSL Enabled” description=”PARAMSECURE”>
<option value=”-1″>Off</option>
<option value=”0″>Ignore</option>
<option value=”1″>On</option>
</param>
</params>
<advanced />
</state>
</metadata>

只需照葫芦画瓢即可了,按自己需要添加text/radio/image类型的参数。那么上面自定义的bg_image参数如何读出呢?在templates里面的html override里,例如:

/templates/mytemp/html/com_content/article/default.php

可以如此读出bg_image:

<?php $img_src = $this->params->get(‘bg_img’); ?>

<?php if($img_src != “”) :?>
<img src=”/images/stories/bg/<?php echo $img_src; ?>”/>
<?php endif; ?>

完。

Leave a Reply

Your email address will not be published. Required fields are marked *