User tests: Successful: Unsuccessful:
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.
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:
<?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.
Status | New | ⇒ | Pending |
Labels |
Added:
?
|
As you can see in the module chromes of protostar and pretty much all templates:
function modChrome_well($module, &$params, &$attribs)
{
if ($module->content)
{
...
}
}
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,
if the module exist and published and available on current page then it must be counted, no matter it empty or not
Ok, I'll just hack my way around the weird issues in Joomla again.
Closed.
Status | Pending | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2015-07-31 11:36:25 |
Closed_By | ⇒ | nonumber |
Can we re-open this please?
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.
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....
Labels |
Added:
?
|
Milestone |
Added: |
Milestone |
Added: |
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.
And then imagine a screnario where you etc build a sidebar because module exists, but there really isn't any content in the module it self, resulting in an empty sidebar....
It would be a nice feature although i don't really see how to accomplish this without rendering modules twice...
As discussed in #7606 it isn't possible for Joomla to check this the way I want to.
For the countModules to know if a module is empty, it would need to render the modules first.
That is not how the order of things in the template rendering work.
Also, you can't just check for the $module->content, as only html modules have that.
Also you run into other side issues:
What is empty? Is an empty <p></p>
empty? What about an empty list or div? And if so, also when they have classes? These elements might get replaced/filled via ajax.
What if a module has no actual html output but only adds scripts/styles to the document?
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.
If you want to change that you open up a whole can of B/C issues.
I was really just posting back to acknowledge I was wrong
OK :)
I was wrong too in thinking I could fix it!
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
Co-founder Joomla! and OpenSourceMatters Inc.
http://brian.teeman.net/