You can restrict or grant access to your desired content by placing either {show}
or {hide}
plugin tags around it.
Inside the opening tag, enter the desired conditions with a condition="value"
syntax, which you might recognise from how html works.
Basic Examples
For example, to show a piece of text only to guests (not logged-in visitors), you can do:
{show accesslevels="Guest"}You are not logged in yet!{/show}
Each condition can also have multiple values, separated with a comma. For example, to hide a piece of text during the weekends:
{hide days="6,7"}Call us now!{/hide}
You can place any type of content between the {show}
and {hide}
plugin tags. So also rich content and images. And you can place these {show}
and {hide}
plugin tags right into your WYSIWYG editor.
Condition Sets
Conditional Content comes with the ability to save and reuse complete Condition Sets. These sets can contain one or more rules in all sorts of combinations.
And the syntax is super simple:
{show condition="My Special Rules"}
This text will only show if my Condition Set passes.
{/show}
The great advantage is that you can reuse the same Condition Set in different Conditional Content tags. But also reuse them in Advanced Module Manager and ReReplacer Pro!
Another advantage is that you can create complex conditions containing multiple rules that are grouped and mix different matching methods (ALL / ANY). While the syntax remains sweet and short. Just the condition="..."
attribute is necessary.
And a third advantage is that you can name the condition set to make it easier to understand what is going on.
For instance, you might struggle a bit when trying to understand:
{show menuitems="23,57,108"}...{/show}
Placing this in a well-named Condition Set will save you some brain cells every time you go back to that content:
{show condition="Legal Pages"}...{/show}
And the last advantage (but you can probably think of more) is that the Condition Sets give you the ability to use more Rule types and settings. The inline conditions only support a subset of the available conditions and do not offer the ability to use Rule settings, like "Also on child items", etc.
Alternative Content
Conditional Content also offers the ability to display alternative content when the set conditions are not met. This can be accomplished by either using a {show-else}
or {hide-else}
tag.
This example displays a message based on whether a visitor is or is not logged-in.
{show accesslevels="Guest"}
You are not logged in yet!
{show-else}
You are logged in now!
{/show}
With the Joomla 4 version of Conditional Content, you can also add conditions inside the {show-else}
or {hide-else}
tags, allowing you to chain conditions:
{show accesslevels="Guest"}
You are a Guest.
{show-else accesslevels="Super User"}
You are a Super User.
{show-else} You are a Registered User.
{/show}
Multiple Conditions
You can also combine multiple conditions and use them at the same time:
{show accesslevels="Guest" device="mobile"}
This text will only show for not-logged visitors from mobile devices.
{/show}
However, it is probably easier to use the above mentioned Condition Sets. The Condition Sets give you a lot more power and possibilities. And if you give it a useful name, the syntax is a lot more readable too:
{show condition="Mobile Guests"}
This text will only show for not-logged visitors from mobile devices.
{/show}