首页 » 后端 » Joomla! » 正文

Joomla!中jdoc:include的style属性详解

发布者:站点默认
2011/10/4 浏览数(2,264) 分类:Joomla! Joomla!中jdoc:include的style属性详解已关闭评论

Joomla!加载模块通常有的两种方法

方法1:

<?php echo mosLoadModules('userPosition','-2');?>

方法2:

<jdoc:include type="modules" name="userPosition" style="xhtml" />

mosLoadModules中第2个参数与jodc:include中style属性的对应关系:
   1 : horizontal
   0 : normal
  -1 : raw
  -2 : xhtml
  -3 : rounded

mosLoadModules中style()几种属性值的区别:

省略属性值、即默认

使用一个2行1列的表格封装模块,第1行单元格中显示模块标题,第2行单元格中载入模块代码。

属性值:0

默认参数,同一位置的模块将显示在一个数列中,下面代表他的显示输出:

<!--Individual module-->
	<table class="moduletable[suffix]" cellspacing="0" cellpadding="0">
		<tr>
			<th valign="top">这里是模块标题</th>
		</tr>
		<tr>
			<td>
				这里是模块内容
			</td>
		</tr>
	</table>
<!-- Individual module end -->

属性值:1

同一位置上的模块将水平显示,各个模块将分别被置于水平的间隔中,如下显示输出:

<!-- Module wrapper-->
	<table border="0" cellspacing="1" cellpadding="0" width="100%">
		<tr>
			<td align="top">
				<!--Individual module -->
				<table class="moduletable[suffix]" cellspacing="0" cellpadding="0">
					<tr>
						<th valign="top">这里是模块标题</th>
					</tr>
					<tr>
						<td>
								这里是模块内容</td>
					</tr>
				</table>
				<!--Individual module end -->
			</td>
			<td align="top">
				这里是下一个模块的输出位置、又一套table标签
			</td>
		</tr>
	</table>
<!-- Individual module end -->

属性值:-1

模块将被显示为一排,但不显示模块的title部分。

属性值:-2

模块将显示为X-mambo格式,如下显示:

<!--Individual module-->
	<div class="moduletable[suffix]">
		<h3>这里是模块标题</h3>
		这里是模块内容
	</div>
<!--Individual module end-->

属性值:-3

除将模块名称显示在h3标签中之外,用多个div容器嵌套封装模块,以通过 CSS 技术显示圆角。

自定义style的代码输出格式

如果“horizontal、normal、raw、xhtml、rounded”不能满足你的要求,你还可以创建自己的style,步骤为(摘自“Applying custom module chrome”(英文)):

第一步:创建modules.php。

位置:PATH_TO_JOOMLA/templates/TEMPLATE_NAME/html/modules.php

第二步:添加代码(大致为以下内容)。

<?php
function modChrome_STYLE($module, &$params, &$attribs){ // STYLE为自定义style名称
	echo '<dl class="catMod">';
	if ($module->showtitle){
		echo '<dt>' .$module->title .'</dt>';
	}
	echo '<dd>';
	echo $module->content;
	echo '</dd>';
	echo '</dl>';
}
?>

下边这是文章中给出的示例,包含参数和属性的演示,代码最后一行我将用法示例复制了过来:

<?php
function modChrome_custom( $module, &$params, &$attribs ) {
	if (isset( $attribs['headerLevel'] )) 
	{
		$headerLevel = $attribs['headerLevel'];
	} else {
		$headerLevel = 3;
	}

	if (isset( $attribs['background'] )) 
	{
		$background = $attribs['background'];
	} else {
		$background = 'blue';
	}

	echo '<div class="' .$params->get( 'moduleclass_sfx' ) .'" >';

	if ($module->showtitle) 
	{
		echo '<h' .$headerLevel .'>' .$module->title .'</h' .$headerLevel .'>';
	}

	echo '<div class="' .$background .'">';
	echo $module->content;
	echo '</div>';

	echo '</div>';
}
?>
<!-- 用法:-->
<jdoc:include type="modules" name="user1" style="custom" headerLevel="1" background="yellow" />

第三步:使用。

<jdoc:include type="modules" name="userPosition" style="STYLE" />

<完>

点击返回顶部
  1. 留言
  2. 联系方式