Conditional Content

Restrict content based on your conditions in Joomla!

  • Last updated: 22-Jan-2018
  • Version: 2.2.0
  • Types: System plugin Editor button plugin

Do you like Conditional Content?

Rate it!

Tutorial for Conditional Content

There is a Free and a Pro version of Conditional Content.
The parts in this tutorial that only concern the Pro version will be marked with: Pro only

Introduction

Conditional Content is a Joomla! system plugin (and editor button plugin).
You can restrict or grant access to content (text, images, etc.) on any page based on a wide selection of conditions.

How to use it (syntax)

You can restrict or grant access to your special content by placing either {show} or {hide} tags around it. Within each opening tag add the desired conditions.

You can place the {show} and {hide} tags right into your WYSIWYG editor. Either type these in manually or use the Conditional Content editor button.

For example, to show a piece of text only to guests (not logged in visitors), you can do:

{show access="Guest"}You are not logged in yet!{/show}

Or hide text during the weekends:

{hide days="6,7"}Call us now!{/hide}

You can place any type of content between the {show} and {hide} tags. So also rich content and images.

Alternative Content

Conditional Content also offers the ability to display alternative content when set conditions are not met. This can be accomplished by either using a {show-else} or {hide-else} tag.

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

Examples

Here are a few examples that demonstrate the flexibility and power of Conditional Content:

User Access

Present guests with message that they are not logged in:

{show access="Guest"}You are not logged in yet!{/show}

Alternative Content

Display message based on whether visitor is not-logged or logged in:

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

Devices

Show mobile version image on mobile devices by rendering "-MobileVersion" image suffix:

<img src=/images/coupon{show device="mobile"}-mobile_version{/show}.jpg

Days of the week

Hide a message on weekends:

{hide days="6,7"}Call us now!{/hide}

Conditions

Conditional Content supports a wide selection of conditions.

These conditions define when or to whom you want to show the content.

If you click on the Conditional Content editor button, you will be presented with all the available conditions.

The different conditions have 3 states:

  • Ignore (default)
  • Include
  • Exclude

By default the condition is are ignored, meaning the condition is not used.
To use a condition, you set the option to Include or Exclude depending on the desired effect.

Include: the content will be shown/hidden in all circumstances that do match that condition.

Exclude: the content will be shown/hidden in all circumstances that do not match that condition.

Matching Method

Should all or any conditions be met?

ALL
The content will be shown/hidden if ALL of below conditions are met.

ANY
The content will be shown/hidden if ANY (one or more) of below conditions are met.
Condition groups where 'Ignore' is selected will be ignored.

Menu Items

Menu Items Select the menu items to assign to.

Home Page

Unlike selecting the home page (default) item via the Menu Items, this will only match the real home page, not any URL that has the same Itemid as the home menu item.

This might not work for all 3rd party SEF extensions.

Date & Time

The date and time assignments use the date/time of your servers, not that of the visitors system.

Date

Start Publishing Enter the date to start publishing
Finish Publishing Enter the date to end publishing
Seasons Select seasons to assign to.

Options: winter, spring, summer, fall (= autumn)
Months Select months to assign to.

Options: 1 - 12 (= January - December)
Days of the week Select days of the week to assign to.

Options: 1 - 7 (= Monday - Sunday)

Time

Start Publishing Enter the time to start publishing.
Finish Publishing Enter the time to end publishing.

Users

Access Levels Select the access levels to assign to.
User Group Levels Select the user groups to assign to.
User IDs Enter the user ids to assign to. Use commas to separate ids.

Languages

Languages Select the languages to assign to.

IP Addresses

IP Addresses / Ranges A comma and/or enter seperated list of IP addresses and IP ranges. For instance:
127.0.0.1
128.0-128.1
129

Geolocating

Geolocating is not always 100% accurate. The geolocation is based on the IP address of the visitor. Not all IP addresses are fixed or known.
To be able to use this assignment, you need to install the Regular Labs GeoIP library.

Continents Select the continents to assign to.
Countries Select the countries to assign to.
Regions / States Select the regions / states to assign to.
Postal Codes A comma separated list of postal codes (12345) or postal code ranges (12300-12500).
This can only be used for a limited number of countries and IP addresses.

Templates

Templates Select the templates to assign to.

URL

URL matches Enter (part of) the URLs to match.
Use a new line for each different match.

Devices

Devices Select the devices to assign to. Keep in mind that device detection is not always 100% accurate. Users can setup their device to mimic other devices.

Options: desktop, tablet, mobile

Operating Systems

Operating Systems Select the operating systems to assign to. Keep in mind that operating system detection is not always 100% accurate. Users can setup their browser to mimic other operating systems.

Browsers

Browsers Select the browsers to assign to. Keep in mind that browser detection is not always 100% accurate. Users can setup their browser to mimic other browsers

Options: Chrome, Firefox, Edge, MSIE, Opera, Safari

Components

Components Select the components to assign to.

Tags

Tags Enter the tags to assign to. Use commas to separate the tags.

Joomla! Content

Page types Select on what page types the assignment should be active.

Options: archive, article, categories, categoryblog, category, featured, form
Categories Select the categories to assign to.
Articles Select the articles to assign to.

Custom PHP

Custom PHP Enter a piece of PHP code to evaluate. The code must return the value true or false.

For instance:
return ( $user->name == 'Peter van Westen' );

What about caching?

Depending on how you set up caching in your Joomla setup, the content in which you place the {show} or {hide} tags can be cached too.
This may have an undesired affect on what content is shown. This also depends on what conditions you use.

Joomla generally caches pages on a page (url) and language level. So it should not matter when that content is cached, Conditional Content will still output what you expect.

For other conditions, you might want to change some stuff in how the content is cached.
When using the Conditional Content tags in a module, you could for instance switch off the caching for that module.
In some 3rd party caching extensions you can also switch off caching for certain scenarios.

Settings

Conditional Content has some options, giving you control over how it works and behaves. Here is the full list of the options you can find in the Conditional Content system plugin settings:

Advanced Options

Show Tag The word to be used in the tags.

Note: If you change this, all existing tags will not work anymore.
Hide Tag The word to be used in the tags.

Note: If you change this, all existing tags will not work anymore.
Tag Characters The surrounding characters of the tag syntax.

Note: If you change this, all existing tags will not work anymore.

Options: {...}, [...], {{...}}, [[...]], [:...:], [%...%]
Disable on Components Select in which frontend components NOT to enable the use of this extension.
Remove in Disabled Components If selected, the plugin syntax will get removed from the component. If not, the original plugins syntax will remain in tact.
Enable in administrator If enabled, the plugin will also work in the administrator side of the website.

Normally you will not need this. And it can cause unwanted effects, like slowing down the administrator and the plugin tags being handled in areas you don't want it.

Editor Button Options

Button Text This text will be shown in the Editor Button.
Enable in frontend If enabled, it will also be available in the frontend.

Installation

You can either install Conditional Content by using the core extension manager available in the Joomla! Administrator Control Panel, or by using the powerful Regular Labs Extension Manager.

Note: When updating Conditional Content, you do not need to uninstall it first. The package will update all the files automatically.

Keep in mind that when you update to a major new version (or uninstall first), you might lose some configuration settings.

Regular Labs Extension Manager

It is very easy to install/update any Regular Labs Extension using the Regular Labs Extension Manager.

Please see the Tutorial for the Regular Labs Extension Manager for more detailed information...

Joomla! Extension Manager

To install via the Joomla! Extension Manager, just follow these steps:

  1. Log into your Joomla administrator;
  2. In the menu, choose: Extensions >> Extensions;
  3. Choose the tab: Install from Web (or enable it if you haven't done so yet);
  4. Select the search field and enter Conditional Content and hit enter;
  5. Click on the Conditional Content listing;
  6. Click on Install;
  7. Click on Install to confirm.
Joomla! Installer - Install from Web

Or if you need to install the Pro version or cannot install via the 'Install via Web' method for some reason:

  1. Download the extension install file (.zip);
  2. Log into your Joomla administrator;
  3. In the menu, choose: Extensions >> Extensions;
  4. Choose the tab: Upload Package File;
  5. Click on the Choose File button and select the extension zip;
  6. Click on Upload & Install.
Joomla! Installer - Upload Package File

If you have problems installing Conditional Content, please try the manual installation process as described here: docs.joomla.org/Installing_an_extension