joomla 3.0将变量从索引传递到视图

时间:2013-04-23 23:16:41

标签: joomla3.0

我正在尝试将索引页面中的变量传递给文章视图。基本上div的宽度需要根据是否有侧边栏来改变。

的index.php:

if ($this->countModules('position-1')&$this->countModules('position-3')){
    $content_margin = 'contentCenter';
}elseif ($this->countModules('position-1')&!$this->countModules('position-3')){
    $content_margin = 'contentRight';
}elseif (!$this->countModules('position-1')&$this->countModules('position-3')){
    $content_margin = 'contentLeft';
}else{
    $content_margin = '';
}

如何访问组件中的$ content_margin变量?

<jdoc:include type="component" class="<?php echo $content_margin; ?>" />

1 个答案:

答案 0 :(得分:1)

我宁愿尝试这样的事情:

<div class="<?php echo $content_margin; ?>">
    <jdoc:include type="component" />
</div>

您不需要将此变量传递给组件,只需为CSS类提供不同的宽度。

如果您想计算组件中的模块数量,可以查看this链接