?
avatar korenevskiy
korenevskiy
3 Feb 2020

Is your feature request related to a problem? Please describe.

It is not possible to change the display of the module itself in the module code.
In the module, I make a check to display the module only for a Component, only for a Category, only for an Article, only for a menu item, or only for Mobile devices. After checking, I forbid showing the module. For example, you don't need to show a slide show on mobile devices. Or showing the hall diagram, the theater should only be shown for a specific hall.

**mod_MyModule.php**
$is_mobile_device = MyModuleHelper::Is_Mobile();
if($is_mobile_device == true){
    $module->published = false;
    return "";
}
//Other normal module code.

After show site.

<div class="grid-child container-sidebar-left">
</div>

In html code showed empty tag after disabled module.

Аfter, the page has an empty column. the entire length of the site.

Describe the solution you would like to get.

Please check the show (property published) of the module after calling this module.

avatar korenevskiy korenevskiy - open - 3 Feb 2020
avatar joomla-cms-bot joomla-cms-bot - change - 3 Feb 2020
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - labeled - 3 Feb 2020
avatar korenevskiy korenevskiy - change - 3 Feb 2020
The description was changed
avatar korenevskiy korenevskiy - edited - 3 Feb 2020
avatar korenevskiy korenevskiy - change - 3 Feb 2020
The description was changed
avatar korenevskiy korenevskiy - edited - 3 Feb 2020
avatar korenevskiy korenevskiy - change - 3 Feb 2020
The description was changed
avatar korenevskiy korenevskiy - edited - 3 Feb 2020
avatar SharkyKZ
SharkyKZ - comment - 14 Feb 2020

You shouldn't be disabling the module at this point. Early return is fine (although would be better done in the layout to give users control). See PR #19416 for possibility of excluding empty modules when counting modules in the template.

avatar korenevskiy
korenevskiy - comment - 16 Feb 2020

@SharkyKZ Do you suggest calling an empty layout file in the module?
mod_MyModule.php

$is_mobile_device = MyModuleHelper::Is_Mobile();
if($is_mobile_device == true){
    $module->published = false;
    require ModuleHelper::getLayoutPath('mod_mymodule', 'empty');
    return "";
}
//Other normal module code.

Then file layout /tmpl/empty.php it is file 0byte.

avatar Bakual
Bakual - comment - 16 Feb 2020

If a module is displayed or not on mobile, can be controlled using the respective display class of Bootstrap (or the framework used by the template). You don't need to do that in your module.

If your module has no output for the respective page, you can return like eg done in the Related Items module: https://github.com/joomla/joomla-cms/blob/staging/modules/mod_related_items/mod_related_items.php#L24-L27

You can do that in the module class or in the layout itself.

avatar korenevskiy
korenevskiy - comment - 17 Feb 2020

@Bakual
This module is loaded at the Position: bottom-a

$list = JModuleHelper::moduleCache($module, $params, $cacheparams);
if (!count($list)){
	return;
}

Reloading the page
Look at the page code, see.

<div class="grid-child container-bottom-a">
	</div>

This left an empty template tag.

	<?php if ($this->countModules('bottom-a')) : ?>
	<div class="grid-child container-bottom-a">
		<jdoc:include type="modules" name="bottom-a" style="cardGrey" />
	</div>
	<?php endif; ?>

The template thinks that there is a module there, and therefore shows an empty tag. And an empty tag is an empty space and an empty padding.

avatar korenevskiy
korenevskiy - comment - 17 Feb 2020

This is a big mistake. The template should not show an empty tag.
However, module developers do not have to manage Bootstrap and the template. Module developers should just do $module->display = false;
But I want to say that this is a CMS error.

avatar SharkyKZ
SharkyKZ - comment - 17 Feb 2020

See PR #19416 for possibility of excluding empty modules when counting modules in the template.

avatar mbabker
mbabker - comment - 17 Feb 2020

For the record that PR would be the better fix than some “display” property only known by the ModuleHelper class. You still end up with the same problem of empty tags without fixing the countModules method in the document.

avatar Bakual
Bakual - comment - 17 Feb 2020

The template should not show an empty tag.

@korenevskiy That is handled by the template and the module chromes which is also a template responsibility. The template and its chromes decides if it wants to show an empty tag or not.
Not a module issue by itself.

Fixing the countModules method indeed would make the life for templates much easier in that regard.

avatar korenevskiy
korenevskiy - comment - 28 Feb 2020

@mbabker

For the record that PR would be the better fix than some “display” property only known by the ModuleHelper class. You still end up with the same problem of empty tags without fixing the countModules method in the document.

I use the Protostar and Cassiopeia template, but the templates show an empty tag if there are empty modules.

avatar korenevskiy
korenevskiy - comment - 28 Feb 2020

Friends, tell me, is this issue being resolved or not?
.
I can solve it at home with crutches. It shouldn't be like this, it's a real mistake that needs to be solved.

avatar Bakual
Bakual - comment - 28 Feb 2020

As said, the correct approach is #19416. That one is RTC but not yet merged.

I don't know if something is still missing after that PR is merged. You could test that and help us figuring that out.

avatar Quy Quy - change - 13 Mar 2020
Status New Closed
Closed_Date 0000-00-00 00:00:00 2020-03-13 00:59:42
Closed_By Quy
avatar Quy
Quy - comment - 13 Mar 2020

Closing since #19416 has been merged. Please open new issue(s) if required.

avatar Quy Quy - close - 13 Mar 2020

Add a Comment

Login with GitHub to post a comment