User tests: Successful: Unsuccessful:
Pull Request for Issue # there somewhere in history, hard to find .
$this->countModules('foobar')
return number of active modules in the position, but do not check whether module has any content, or not (so it will be not visible)
This is one of most annoying things in Joomla! templating to me.
It can happen with 3d modules for display some associated lists (or similar). HtmlDocument::countModules
still count this module as "exists" even if associated list is empty, and so module will not be displayed.
The idea is to allow to count only the module which actually has a content.
I have added flag $withContentOnly
to HtmlDocument::countModules
which allow to do it.
And split ModuleHelper::renderModule
to 2 part ModuleHelper::renderRawModule
(render module content) and ModuleHelper::renderModule
(render module Chrome, trigger the events etc). So HtmlDocument::countModules
will trigger rendering only for module content ModuleHelper::renderRawModule
and count only the modules which actually have the content.
It a bit tricky.
First make override to mod_custom, call it empty.php
, and remove all content from it. This will imitate the module without content.
Then create 2 mod_custom modules:
"module1" which use override "empty", at position foobar
;
"module2" with some random text and without any override, at position foobar
;
In the index.php of the template add next code:
var_dump($this->countModules('foobar', true)); // Count only modules which has content
var_dump($this->countModules('foobar')); // Count all modules in selected position
int 1
int 2
int 2
int 2
yeap
Status | New | ⇒ | Pending |
Category | ⇒ | Libraries Front End Templates (site) |
Labels |
Added:
?
?
|
I'm really not sure about this - I can see the support emails now. "I've created and published the module but it doesn't appear!".
I'm really not sure about this - I can see the support emails now. "I've created and published the module but it doesn't appear!".
It happens even without this changes
User did not set a position, made incorrect menu assignment, set non existing position etc etc... usual things
But, by default I keep an old behavior.
ah, I think you missed the idea.
it does not hide the module, does not prevent displaying it.
But it allow template developer to do action (eg display the position) depend if module has a content or not, like this:
<?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; ?>
Currently the invisible module (module without content) still will be non visible, but template will render empty wrapper, that often a problem.
<div class="grid-child container-bottom-a"></div>
Current pull request prevent it,
if you do:
<?php if ($this->countModules('bottom-a', true)) : ?>
<div class="grid-child container-bottom-a">
<jdoc:include type="modules" name="bottom-a" style="cardGrey" />
</div>
<?php endif; ?>
And position bottom-a
has invisible module, then the wrapper will not be rendered.
Is the title part of the content?
Is the title part of the content?
nope
Nice idea, it is needed to finally get real module counting
Looking at code changes,
i see that the raw rendered content (without plugin event triggered) of the modules, that is created during module counting
is cached so that it is not re-created when modules content is displayed,
thus no performance penalty or other side-effects because of having the module created twice
but what about the cases that full module content is created by by the event onRenderModule ?
in such a case the module will be considered empty but countModules, but it will not be
Are there such template frameworks that do this ?
such frameworks also have their own "countModules" thing ?
but what about the cases that full module content is created by by the event onRenderModule ?
that would be very strange
if the module content are created by some plugin, it just not right.
Are there such template frameworks that do this ?
I do not know, I do not use them.
But when I do new site/template I use similar thing, I have helper wich render a modules and count the result.
Because renderRawModule(...) is public I would love to see this method in Joomla to get rid of annoying workarounds for this issue.
Conflict fixed.
I think about rename the events:
onRenderModule
=> onRenderModuleChrome
onAfterRenderModule
=> onAfterRenderModuleChrome
that more accurate to what is actually rendered. But it not b.c. of course. Thoughts?
From a quick look on the code, do I see it right that a module is rendered twice now? It can also happen that a module is executed even when it is not rendered then through an include?
do I see it right that a module is rendered twice now?
Nope, you see it wrong
Look at renderModule()
and renderRawModule()
,
Module object has a flag/prperty: contentRendered
, that is used to be sure that the module content are rendered only once.
It can also happen that a module is executed even when it is not rendered then through an include?
hm, the rendering process stay the same as was before, it just split to 2 part:
Title |
|
Title |
|
@sanderpotjer I will check when will have a more time, the conflict pretty complex
Labels |
Added:
?
Removed: J4 Issue ? |
Labels |
Added:
?
|
conflict fixed :)
Labels |
Removed:
?
?
|
I have tested this item
works fine for me. I think it's a very usefull patch, especially for template developers.
I have tested this item
Counted the Modules correctly
I have tested this item
It works fine! Thanks nice function.
Is the title part of the content?
I would say it is
Labels |
Added:
Conflicting Files
|
conflict fixed
Labels |
Added:
?
Removed: Conflicting Files |
Maybe this pr can be considered as beta blocker since it has some bc problems but it seems from all the commenters that this is the right way to solve a problem that was unsolvable for joomla 3.0.
Also i see only succesfull tests so maybe rtc after conficts?
it does not block anything
Status | Pending | ⇒ | Ready to Commit |
RTC.
So I really dunno what to do with this. It's probably more expected behaviour. But presumably by definition will break the entire purpose of What Nothing https://extensions.joomla.org/extension/what-nothing/ which entirely exploited this behaviour...
I'm kinda leaning to it's one of these things where if it was new I'd do it this way but at this point it's so expected I'm going to break more websites than I fix by merging it?
but at this point it's so expected I'm going to break more websites than I fix by merging it?
hm, why it break? it does not change default behavior, it just extending it ;)
Everyone who use $this->countModules('foobar')
will get "old result",
New is $this->countModules('foobar', true)
with extra boolean parameter
@regularlabs tagging you so you can give some feedback here if you'd like. Otherwise will merge this in the next week or so.
No feedback needed from me.
Status | Ready to Commit | ⇒ | Fixed in Code Base |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2020-03-09 11:57:21 |
Closed_By | ⇒ | wilsonge | |
Labels |
Added:
?
|
Thanks!
@zero-24 this need to be documented as possible compatibility break for stuff like
$this->countModules( 'user1 or user2' )
, that was dropped in J4, because deprecated.
And maybe warning about it at https://docs.joomla.org/Customising_the_way_modules_are_displayed
I tried to edit that page, but not found how to make it
If i remember correctly the problem comes when the module has a title but no content. See #3705