Documentation 2.x and 3.x

Parameters

You can store and retrieve configuration values (parameters) for the system and/or a plugin.

What it is

Most plugins need to store some configuration values (parameters). ImpressPages CMS provides default service to store common types of configuration values:

  • string (multilingual or not)
  • text (multilingual or not)
  • wysiwyg (multilingual or not)
  • integer (multilingual or not)
  • boolean

All available options can be managed in Developer -> Modules Config tab. On the left you choose plugin which you want to configure, then on the right you create / view / edit configuration options combined into groups.

Standard -> Configuration tab does exactly the same but it is designed for less experienced users and provides only the most used options. If you want to show some configuration options on Standard -> Configuration tab, remove checkbox from "Admin" field of that parameter.

Important! Do not delete any default parameters! It will break the system!

For the maintenance purposes for your theme or plugin, create a separate parameters group.

ImpressPages CMS parameters management

How to retrieve stored values

Values of the parameters can be retrieved using parameters service anywhere in your code (see below).

<?php

//use this syntax to get parameter value anywhere within your code

$parametersMod = \Ip\ServiceLocator::getParametersMod();
$siteEmail = $parametersMod->getValue('standard', 'configuration', 'main_parameters', 'email');
echo $siteEmail;

?>

First two parameters of getValue() method ('standard' and 'configuration') uniquely identifies module/plugin on the system. This is what you choose on the left in parameters management screen. Last two parameters ('main_parameters' and 'email') are "parameters group" and "parameter name" accordingly.

The above example will return us an email parameter from main_parameters parameters group from configuration module from standard module group. Which is a default email of the website.

There is a short syntax to use parameters within View files:

<?php echo $this->par('standard/configuration/main_parameters/email') ?>

Often parameters need to be escaped to avoid HTML injection. There is short function for that, too:

<?php echo $this->escPar('standard/configuration/main_parameters/email') ?>

How to set a parameter value

To set a value, use setValue method as in example below:

<?php
//use this syntax to get parameter value anywhere within your code
$siteEmail = 'webmaster@example.com';
$parametersMod = \Ip\ServiceLocator::getParametersMod();
$parametersMod->setValue('my_plugin_group', 'my_plugin', 'main_parameters', 'email', $siteEmail);
?>

Your own plugins and configuration values

You can create your own configuration values using Developer -> Modules config screen and access them from the code. You can also use Developer -> Modules exp/imp tab to export and import these values.

If you want to give website administrator some configuration options, this is the right way to do that.

Write a comment

You must be logged in to comment.