Joomla模块可以“知道"吗?它在什么位置? [英] Can a Joomla module "know" what position it's in?
问题描述
我是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屋!