« Back to Product

Documentation

IPS_GetPresentationValue

 mixed IPS_GetPresentationValue (string $PresentationID, int $VariableType, array $Parameters) 

Parameters

PresentationID

The ID of the presentation, formatted as GUID

VariableType

The variable type for which the value is to be returned (0 (VARIABLETYPE_BOOLEAN): Boolean, 1 (VARIABLETYPE_INTEGER): Integer, 2 (VARIABLETYPE_FLOAT): Float, 3 (VARIABLETYPE_STRING): String)

Parameters

The parameters of the presentation as key => value pairs, e.g. ['MIN' => 0, 'MAX' => 100]

Returns

The preview value of the presentation. The type depends on the presentation and the variable type.

Description

The function returns the value the presentation PresentationID shows in its preview, e.g. in the variable dialog or in the template manager. The presentation defines this value in presentationValue (see IPS_GetPresentation):

  • If a fixed value is defined there (e.g. TRUE for the switch), it is returned unchanged. VariableType and Parameters have no effect then.
  • If PHP code is defined there, it is executed and its return value is returned. In the code, the Parameters as well as the VariableType as VARIABLE_TYPE are available in $_IPS. The parameters are not completed with default values – if the code needs a parameter (e.g. MIN, MAX and STEP_SIZE for the slider), it must be passed.

If the code does not return a valid JSON-encodable result, the function fails with "Invalid JSON for presentation value: …". If the presentation does not exist, the function fails with "Presentation with ID … not found!", for an invalid GUID with "PresentationID … is not a valid GUID".

Together with IPS_GetPresentationFormat this allows creating a preview of a presentation.

Example

// Fixed preview value
var_dump(IPS_GetPresentationValue('{60AE6B26-B3E2-BDB1-A3A1-BE232940664B}' /* Switch */, VARIABLETYPE_BOOLEAN, []));
// returns: bool(true)

// Preview value from PHP code
var_dump(IPS_GetPresentationValue('{3319437D-7CDE-699D-750A-3C6A3841FA75}' /* Value Presentation */, VARIABLETYPE_FLOAT, []));
// returns: float(123.456)

var_dump(IPS_GetPresentationValue('{6B9CAEEC-5958-C223-30F7-BD36569FC57A}' /* Slider */, VARIABLETYPE_FLOAT, ['MIN' => 0, 'MAX' => 100, 'STEP_SIZE' => 1]));
// returns: float(42)
Any questions?