Can a Joomla module “know” what position it's in?

后端 未结 5 1555
我寻月下人不归
我寻月下人不归 2021-01-06 19:00

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

5条回答
  •  感动是毒
    2021-01-06 19:27

    I'm going to disagree with Hanny. I think the answer is no, not as you describe.

    The template knows when it has reached a module position, and it gets a list of modules assigned to that position, then calls for them to be rendered. But it doesn't pass that information on. It's not stored in JApplication or JDocument etc either (like, nothing stores where in the template the rendering is up to or anything).

    There are some hacky ways to almost get what you want though. If you know the template positions you need to search (sadly there's no easy method for getting this from the template - otherwise you could parse your template's .XML file for elements...), then you could do something like:

    module == 'mod_MYMODULE')
            {
                $found_in = $cur_position;
            }
        }
    }
    
    if ($found_in)
    ...
    

    Of course, this doesn't work well if your module is included multiple times on the page, but maybe that's an assumption you can make?

    Otherwise it'd be up to hacking the core - you could use a JDispatcher::trigger() call before the template calls a module, set some var etc. Unfortunately there's no such event in core to start (a pre_module_render or something).

提交回复
热议问题