Conditional content code in a custom module

Search
Other Bug Reports questions
Forum

Conditional content code in a custom module

Fabio's Avatar Fabio
I found out that Conditional content code doesn't work if I insert it in a custom module.

Found out more here: forum.joomla.org/viewtopic.php?f=814&t=997325

Is it normal, or is there a bug?

Thanks
Peter van Westen's Avatar Peter van Westen ADMIN
Conditional Content should work in any content that is inside your websites direct HTML output.
So also inside modules.

Going by that post on the Joomla Forum, you start with the tag {show-else}. That is not correct syntax.
Read the documentation carefully on how Conditional Content works:
docs4.regularlabs.com/conditionalcontent
Please post a rating at the Joomla! Extensions Directory
Fabio's Avatar Fabio
Thank you for your reply, Peter.

I do not start with the tag {show-else}.

I write directyly in the article the following opening conditional content tag:

{show matching_method="any" date="2025-09-25 08:00" usergrouplevels="Supporters"}

Then, I have the article text I want to show only to Supporters.

Below that text, I place a custom module with the last part of conditional content inside

<p style="text-align: justify;">{show-else}</p>
<p style="text-align: justify;"><strong><span style="font-family: arial, helvetica, sans-serif; font-size: 14pt; background-color: #ffcc00;"><span style="color: #ff0000;">Central part temporarily omitted. Full article available in preview only to Supporters of Waterwind.it. To become a Supporter,&nbsp;<a href="en/register.html" target="_blank" rel="noopener" style="background-color: #ffcc00;">click here</a></span><span style="color: #ff0000;">.</span></span></strong></p>
<p style="text-align: justify;">{/show}</p>

It should work like in your docs example, where you suggest:

{show accesslevels="Guest"}
You are not logged in yet!
{show-else}
You are logged in now!
{/show}

But, putting the last part of the code (from {show-else}) inside the custom module, it works, but creates conflict with some template positions, beacuse it creates a </div> tag without a corresponding <div> before.
It works without conflicts, only if I write the the closing conditional content code directly inside the article text.


Regards
Peter van Westen's Avatar Peter van Westen ADMIN
You can't put half of the {show}...{/show} in a different content place.
That will break your HTML structure. This is expected behavior.
EVERYTHING (including HTML and opening and closing tags) within the {show}...{show-else} or {show-else}...{/show} will be removed from your HTML output.

So this is not a bug, but an incorrect use of the extension.
Please post a rating at the Joomla! Extensions Directory
Fabio's Avatar Fabio
Ok, thank you for your kind reply. Clear.

Just consider (maybe in future versions of the extension) that part of the code may be different each time (e.g. as for the date from which to start a particular condition), while the other part of the code may be always the same (in my case, the alternative content to show). So, it may be useful to have the chance not to write it every time, but to recall it from a pattern.

Thank you
Peter van Westen's Avatar Peter van Westen ADMIN
You should look into using Snippets.
Then you can leave the {show} tags alone, and only change the content part using Snippets.
regularlabs.com/snippets
Please post a rating at the Joomla! Extensions Directory
You can only post on this forum if you log in