开发者

Loading two template files of same module in two positions

I am working on a new project and I am using Joomla version 1.5.22. I need to display one horizontal search form in the middle of home page and the same search form in vertical style in all other pages but in left position.

So what I did is, I created two template files one for horizontal search(horizontal.php) and other for vertical search (vertical.php) and in mod_modulename.php I tried to load the respective modules based on a certain condition and changed the position left or middle according to it. The positions are changed in the database to get effected in the admin panel.

if(condition) {
   modModulenameHelper::changeToVertical($position);//to change position in database to left 
    require( JModuleHelper::getLayoutPath( 'mod_modulename', 'vertical'));
    } 
else {  
    modModulenameHelper::changeToHorizontal($position);//to change position in database to middle
    require( JModuleHelper::getLayoutPath( 'mod_modulename', 'horizontal'));

But I am not getting 开发者_如何学Pythonthe correct output. It is loading the respective modules based on the condition. But the position is not assigned at first. And if I press Ctrl+F5 or refreshes, the page will be loaded with the desired output.

Why is this happening? Any Solution??


The problem is that you are changing the position after the fact. By the time you are changing the position, Joomla has already assigned the module to a position. It's an order of operations thing.

Instead, why not just use 2 instances of the module? Rather than going through this trouble, simply add a parameter to the module that allows you to select horizontal or vertical, then assign one to the home page menu item and another to the rest of the pages. This would also allow for putting the module in other positions instead of hard coding it in to the module.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜