New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed issue with countModules also counting empty modules #7594
Conversation
Templates use the ```$this->countModules('myposition')``` to determine whether or not to show a position (and surrounding html). However, when a module is empty (no content), the ```countModules``` is not affected. This can result in positions being shown with no modules in it. This PR fixes the issue by only counting the modules that do not have an empty content. #### Testing Instructions Easiest way to test with an empty module is to use Advanced Module Manager, as that will make the content truly empty even if the module has an empty ```<p></p>``` tag. So just make a Custom HTML Module and leave the content area empty. Assign it to a module position (that has no other modules assigned to it). Like manually entering ```testempty``` in the module position field. Then in your template place this somewhere: ``` <?php echo "\n\n<pre>==========================\n"; echo 'Module count for position "testempty": ' . $this->countModules('testempty'); echo "\n==========================</pre>\n\n"; ?> ``` Before this patch it will show a count of 1, after a count of 0.
What if someone is using the module JUST to display the title On 31 July 2015 at 11:05, Peter van Westen notifications@github.com wrote:
Brian Teeman |
As you can see in the module chromes of protostar and pretty much all templates:
So templates are only outputting the module if it has content anyway. |
Thats true at least for a custom html module - not tested others |
Then this patch won't affect that and will still show it. |
sorry I not agree with this changes also, |
Ok, I'll just hack my way around the weird issues in Joomla again. |
Can we re-open this please? This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/7594. |
At best this is a "discuss for 4.0" item; re-opening it and trying to push it for 3.x is a no go IMO as it causes a pretty big behavioral change (not rendering modules if the content is empty which can affect site layouts pretty bad). And honestly, I don't think there's a bug in the current behavior; if the conditions are to count all published modules without considering their content then this method behaves as intended. |
Please see: #7606 |
I have to agree with nonumber with this.... I'm with Joomla since v1, have build dozens of sites, and this is a very usefull feature... ATM I have to do workarounds in my template.... This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/7594. |
OK I was completely wrong on this one and now fully understand the issue. This is the scenario I faced and perhaps it will help others to understand it. Let us say that if $this->countModules('myposition') is true we display a right hand column but if the count is false we dont. Now if you have a split menu or any dynamic module such as Article-Categories that is set to be published on every page the count will always be true BUT if there are no menu items to be displayed on the page then you end up with a completely empty right hand column. (sadly the proposed fix didnt work for me) |
Yeah, the point was to determine if the modules not only exist in that position, but also produce any content.... So $this->countModules('myposition') only checks for modules, not for content. |
As discussed in #7606 it isn't possible for Joomla to check this the way I want to. Also you run into other side issues: So as far as I can see it, this issue will be there as long as the way Joomla does the template/module rendering stays as it is. |
I was really just posting back to acknowledge I was wrong |
OK :) I was wrong too in thinking I could fix it! |
Templates use the
$this->countModules('myposition')
to determine whether or not to show a position (and surrounding html).However, when a module is empty (no content), the
countModules
is not affected.This can result in positions being shown with no modules in it.
This PR fixes the issue by only counting the modules that do not have an empty content.
Testing Instructions
Easiest way to test with an empty module is to use Advanced Module Manager, as that will make the content truly empty even if the module has an empty
<p></p>
tag.So just make a Custom HTML Module and leave the content area empty. Assign it to a module position (that has no other modules assigned to it). Like manually entering
testempty
in the module position field. And switch on the 'Hide if Empty' option.Or create your own module that returns an empty content.
Then in your template place this somewhere:
Before this patch it will show a count of 1, after a count of 0.