Jump to content

Using expressions in logic

As mentioned in the first step, any valid PHP expression can be used in HTML logic tags. You'll often just be checking if an expression is true or false:

{{if $value}} ... {{endif}}

...but there are many other possibilities.

You can also use normal PHP functions in your expressions. For example, you may need to determine if an array has any items, so PHP's count function is appropriate:

{{if count( $items ) > 0}} ... {{endif}}

Consult the full PHP documentation for the functions and language syntax.

 

Getting values from IPS4

You'll often need to compare values in the software in your expressions. For example, is a particular setting enabled, or does the current user have a member ID.

While you can use the standard PHP approach to get these values, IPS4 contains a number of shortcut 'constants' you can use to simplify your logic. They are used like so:

{{if settings.reputation_enabled}} ... {{endif}}

Behind the scenes, this shortcut gets expanded to the PHP equivalent, meaning it gives you access to all of the available methods and properties of the object it translates to.

The available shortcuts are:

 

request
Translates to \IPS\Request::i().
Access to the request variables. e.g.

{{if request.some_param}}

 

member
Translates to \IPS\Member::loggedIn()
The member object for the current user. e.g.

{{if member.language()->isrtl}}

 

settings
Translates to \IPS\Settings::i().
Obtains system setting values (by setting key). e.g.

{{if settings.auto_polling_enabled}}

 

output
Translates to \IPS\Output::i().
The output object, containing the methods/properties the suite uses to output content. e.g.

{{if count( output.contextualSearchOptions )}}

 

theme
Translates to \IPS\Theme::i()->settings.
Access to the theme settings available for the currently-used theme. e.g.

{{if theme.sidebar_position == 'right'}}

 

cookie
Translates to \IPS\\Request::i()->cookie.
Access to the cookie object. e.g.

{{if isset( cookie.hasJS )}}

 

Consult the PHP framework documentation for the full range of properties and methods available for each class. 


  Report Guide


×
×
  • Create New...