Showing different content using conditional logic

It is possible to alter the content that appears in an article based on special conditions, such as whether the user is logged on or what time of day it is.  This can be particularly useful on the homepage of your website so that guests (new visitors to your website) see information that is interesting to them, but registered users (your trusty customers) see information that is tailored to their sales and service needs. 

A mambot called "mosif" is used to provide this functionality.

The following text is taken from the readme.txt for mosif, and has been reformatted to suit this article:


INFO FOR VERSION 1.11
=====================

Welcome to mosIf!

Version 1.11
Copyright (C) Martin Larsen 2005
This e-mail address is being protected from spam bots, you need JavaScript enabled to view it
http://mosforge.net/projects/mosif/

All rights reserved
MosIf mambot is Free Software
Released under GNU/GPL License : http://www.gnu.org/copyleft/gpl.html

MosIf is a mambot that makes it possible to show content based on certain conditions. It is suited for limiting access to parts of the page to certain users or user groups, or from certain IP addresses. For example you can enclose content in mosIf tags and limit the content to your own IP address; then you can work on the page and test the content knowing that only you can see it. You can also test cookie values and show content based on those values. This makes it easy to implement a simple multi-language site, or you can show prices with or without VAT etc.

MosIf accepts wildcards * and ? which makes it extremely versatile.

MosIf currently supports the following conditions: user name, user type, user group, frontend language, ip address, language, author, browser, date, time, datetime, weekday, and cookie values.

Usage:
{mosif <parameter><operator><list>}some content{else}other content{endif}

<parameter> : username | usergroup | usertype | ip | language | cookie_<name>
<operator>  : = | !=                      Wildcards (*,?) are allowed. ? = any one character, * = any number of characters
<operator>  : <  lt  <  >  gt  >    no wildcards with these operators
<list>      : text[,text]

There is no "less than or equal to" operator etc, but by using the ! negation operator you can achieve the same:
 {if time !lt 14.30} which is equal to "if time is 14.30 or later".

Apropriate values for:
username  : any name like john, batman, wilddog etc.
usergroup : public, registered, special
usertype  : registered, author, editor, publisher, manager, administrator, super administrator
ip        : 127.0.0.1, 212.230.221.7 etc.
language  : en, da, no, it etc.
author    : author name of the given article, {if author=batman} ...
browser   : the current browser version. {if browser=mozilla firefox*} ...
date      : current date in the format yyyy.mm.dd, {if date !lt 2005.09.01} this will show up on September first or later...
time      : current time in the format hh.mm.ss (24 hour clock), {if time gt 08.30}It's time to get up! ....
datetime  : current date and time in the formats above, {if datetime gt 2005.09.01 12}This will show up on September first at 12 o'clock ...
weekday   : current weekday, {if weekday=saturday,sunday}Hurrah, it's weekend!{else}Arg, back to work ...{endif}
cookie_<name> : any cookie name

Cookies must be prefixed with cookie_ such as cookie_language for a cookie called language
Cookies can be set by a link like this:
Select language: <a href="javascript:document.cookie='language=en;path=/';location.reload(1);">English</a>

- You can use {if} as a shorter alternative to {mosif}

- You can nest mosif's by using a qualifier after mosif (or if), for example:

{mosif username=batman}
Hello Batman! It's {mosif.a time gt 23}very late{else.a}not so late{endif.a}
{else}Don't know you!{endif}

You must use the qualifier for each corresponding tags, ie. also {else}

- There is a very handy debug feature which shows you the current values of the supported parameters:
{mosif debug}

This takes no end tag!

NOTES:
1. MosIf tags can span multiple lines
2. Conditions and names are case insensitive
3. You can put a space before and after the commas and equal sign for clarity
4. MosIf constructions CANNOT be nested

Examples:

a) With EQUAL (=):
==================
{mosif username=john}Hello John. Only you can see this!{endif}
{mosif usertype=*administrator}Special content for administrators and super administrators{endif}
{mosif usergroup=registered}You are a registered user on this site.{endif}
{mosif ip=127.0.0.1}This is only visible on the local developer PC.{endif}
{mosif ip=10.0.0.?}Only visible in the network range 10.0.0.0-10.0.0.9{endif}
{mosif language=de}Wie gehts?{endif}
{mosif language=en}How are you?{endif}

b) With NOT EQUAL (!=):
=======================
{mosif username!=john}Everybody but John are allowed to see this!{endif}
{mosif usergroup!=public}You have to be a registered user to see this sentence{endif}
{mosif language!=en}Sorry, this content is only avaiblable in English.{endif}

c) With else:
=============
Hello {mosif username=john,peter,sam}guys. How are you today?{else}Stranger. What are you doing here?{endif}
{mosif ip=212.242.*}Hello to all adsl users from cybercity.dk.{else}Who is your ISP?{endif}
The price {mosif cookie_vat=0}without VAT is DKK 100{else}including VAT is DKK 125{endif}



Views: 1944

Be first to comment this article
RSS comments

Only registered users can write comments.
Please login or register.

Powered by AkoComment Tweaked Special Edition v.1.4.6
AkoComment © Copyright 2004 by Arthur Konze - www.mamboportal.com
All right reserved

 

Search

Recent Comments

Web Business
This is a wonderful opinion. The things mentioned are great ...
10/08/10 05:02 More...
By rickthomas

Yellow Pages Online vs Google ...
I have had a Yellow Pages premium ad since October of last y...
03/03/10 05:50 More...
By lindaleon

Yellow Pages Online vs Google ...
I believe that the deal that was signed last year See ht...
20/05/09 11:13 More...
By jamie

Delivering Your Website On A M...
Does google android have that feature? [URL=http://www.goog...
18/05/09 10:34 More...
By Cooolr

Delivering Your Website On A M...
I can't wait to get myself a phone that can search the inter...
18/05/09 10:33 More...
By Cooolr

Login