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.
Please check the show (property published) of the module after calling this module.
Labels |
Added:
?
|
@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.
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.
@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.
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.
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.
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.
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.
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.
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2020-03-13 00:59:42 |
Closed_By | ⇒ | Quy |
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.