Syntax Guide

Article number: 300867
Last updated: 24 January 2017

Conditional Logic

Sitekit CMS provides a reserved placeholder '<sitekit:if ...>' that can be used to conditionally control the inclusion/exclusion of page elements and HTML markup. Sitekit CMS 'if' statements can be used in variables/variable blocks, templates and page bodies.

These have many uses but one of the commonest is for displaying certain information on the page dependent on whether a user is logged in or not. The other is for hiding all the div containers related to an empty content text block (see example 3).

Note that Sitekit ‘if' statements cannot be nested, it makes their output very unpredictable.

Syntax (XHTML)


<sitekit:if op1="operand-value" operator="operator-value" op2="operand-value">

...any HTML markup or sitekit placeholders go here...

</sitekit:if>

Operand-values can be any of the sitekit magic words, any text string or a http request (see below).

Operator-values can be:

  • = or == (equals);
  • != or !== or <> (not equal);
  • in (op2 contains op1);
  • not in (op2 does not contain op1); or
  • overlaps (see example 4, op1 is a subset or full set of op2)

Syntax (non-XHTML)

<if "operand-value" operator-value "operand-value"> ...any HTML markup or sitekit placeholders go here... </if>

'in' and 'not in' operators cannot be used with the non-XHTML-compliant syntax. The use of the 'sitekit:' namespace is optional with either syntax.

Examples

1) Include some text on your web-page on certain days of the week.

<sitekit:if op1=":::dayofweek:::" operator="in" op2="Saturday,Sunday">

<p>It's the weekend!</p>

</sitekit:if>

<sitekit:if op1=":::dayofweek:::" operator="not in" op2="Saturday,Sunday">

<p>It's a weekday!</p>

</sitekit:if>

2) Toggle a login or logout link dependent on whether the visitor is logged in:

<sitekit:if op1=":::username:::" operator="=" op2="">

<p>Click here to log in</p>

</sitekit:if>

<sitekit:if op1=":::username:::" operator="!=" op2="">

<p>Click here to sign out.</p>

</sitekit:if>

3) Show the block and its container only if it's not empty

<sitekit:if op1=":::thispageinfo.bodylength5:::" operator="!=" op2="0">

<div class="landingPageMainContentItem"> <COMMENT>BODY5</COMMENT> </div>

</sitekit:if>

4) Show the zone named 'right-column' and its elements only if it's not empty (added in 11.0)

<sitekit:if op1=":::zone.right-column.count:::" operator="!=" op2="0">

<div class="landingPageMainContentItem"> <sitekit:zone id="right-column" /> </div>

</sitekit:if>

5) Show the block if the logged in users groups list overlaps the op2 list. (Added in v9.6)

<sitekit:if op1=":::usergroupnamecsv:::" operator="overlaps" op2="admin,editor,publisher">

<div class="landingPageMainContentItem"> …content here… </div>

</sitekit:if>

HTTP Requests in 'IF' Statements

A powerful extension to sitekit:if statements is the ability to make a HTTP Request within the operand of an IF statement. This allows custom web-services to be used to control display of elements within a page.

operand-value syntax: get(url)

HTTP Request Examples

1

<sitekit:if "get(http://test.sitekit.net/test.txt)" = "SUCCESS">

<p>The file 'test.txt' contains just the word 'success'.</p>

</sitekit:if>

2

<sitekit:if op1="Access Denied" operator="not in" op2="get(http://test.sitekit.net/serversidepage.aspx?page=:::promokeyword:::)">

<p>The text will be shown only if the aspx page does not return 'Access Denied' in its output.</p>

</sitekit:if>

3

<sitekit:if op1="1294" operator="in" op2="get(http://test.sitekit.net/admin/ws/userfunctions.asmx/GetSiteID?domainname=:::domain:::)">

<p>This will only show if the domain name of the site corresponds to a siteid of 1294.</p>

</sitekit:if>

4

<sitekit:if op1="iPhone" operator="in" op2=":::user_agent:::">

<p>You appear to be using an iPhone, would you like to redirect to our mobile pages <a href="http://m.sitename.com">here</a> or stay on the site.</p>

</sitekit:if >

Related questions


This article was last updated on 24 January 2017. Did you find it helpful?