Added option to not count empty modules in countModules and getModules #7606
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is an adapted PR of #7594
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 adds the option to not include empty modules in that count.
This can be done by adding
false
as second argument (setting$include_empty
tofalse
):$this->countModules('myposition', false)
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:
Opinion
In my opinion the default for
$include_empty
should befalse
.As people are saying in #7594 that would change behaviour. That is true, but I believe it only changes it in edge cases and only when those edge cases don't want the empty modules to be counted.
However, that isn't worth my time to fight for, so hope this 'addition' instead of a 'fix' does get accepted.
Then it is up to the template developers to implement it.