Joomla 模块可以“知道"吗?它在什么位置? [英] Can a Joomla module "know" what position it's in?

查看:10
本文介绍了Joomla 模块可以“知道"吗?它在什么位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Joomla 的新手(我更喜欢 Wordpress),我有一个关于模块位置的问题.

I'm fairly new to Joomla (I've been more of a Wordpress guy) and I have a question about module positions.

一个模块可以知道它在什么位置吗.例如我可以做这样的事情:

Can a module know what position it's in. For instance can I do something like this:

if(modulePosition =='left'){
    Do this...
}else{
    Do that...
}

这似乎很容易,但我已经搜索了几个小时,但找不到任何可以帮助我解决的问题.我知道有一个 countModules 函数,但据我所知,它只是检查模块是否处于活动状态.

It seems easy enough, but I've searched for hours and can't find anything that will help me with that. I know there is a countModules function but from what I can tell, that just checks to see if the module is active or not.

感谢您的帮助!

推荐答案

我找到了答案!主要归功于@Hanny.他使用模块 id 的想法让我在谷歌上搜索并找到了答案.对于碰巧想在这里做类似事情的任何其他人来说.

I found the answer! Mostly thanks to @Hanny. His idea of using the modules id got me googling for that and I came across the answer. For anyone else that happens to be looking to do something similar here it is.

你使用了一个全局变量 $module(谁想到了,对吧?)

You use a global variable $module (who'd a thought, right?)

所以我的代码现在看起来像这样:

So my code now looks like this:

$class = '';
if($module->position == 'position1'){
     $class = 'class1';
}
and so on...

很简单吧?

要了解您还可以使用全局变量 $module 做什么,只需将其放入您的代码中,看看您可以使用哪些信息:

To find out what else you can do with the global variable $module just put this in your code and see what info you can use:

echo(print_r($module));

感谢您的帮助!

这篇关于Joomla 模块可以“知道"吗?它在什么位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆