Download the PHP package dd/evolutioncms-snippets-ddif without Composer
On this page you can find all versions of the php package dd/evolutioncms-snippets-ddif. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download dd/evolutioncms-snippets-ddif
More information about dd/evolutioncms-snippets-ddif
Files in dd/evolutioncms-snippets-ddif
Package evolutioncms-snippets-ddif
Short Description This snippet compares different values and returns required chunk or string.
License
Homepage https://code.divandesign.ru/modx/ddif
Informations about the package evolutioncms-snippets-ddif
(MODX)EvolutionCMS.snippets.ddIf
This snippet compares different values and returns required chunk or string.
Requires
- PHP >= 5.6
- (MODX)EvolutionCMS >= 1.1
- (MODX)EvolutionCMS.libraries.ddTools >= 0.60
Installation
Using (MODX)EvolutionCMS.libraries.ddInstaller
Just run the following PHP code in your sources or Console:
- If
ddIfis not exist on your site,ddInstallerwill just install it. - If
ddIfis already exist on your site,ddInstallerwill check it version and update it if needed.
Manually
1. Elements → Snippets: Create a new snippet with the following data
- Snippet name:
ddIf. - Description:
<b>2.3.1</b> This snippet compares different values and returns required chunk or string.. - Category:
Core. - Parse DocBlock:
no. - Snippet code (php): Insert content of the
ddIf_snippet.phpfile from the archive.
2. Elements → Manage Files
- Create a new folder
assets/snippets/ddIf/. - Extract the archive to the folder (except
ddIf_snippet.php).
Parameters description
-
operand1- Desctription: The first operand for comparing.
An empty unparsed placeholder (like'[+somePlaceholder+]') will be interpretated as empty string (''). - Valid values:
string - Required
- Desctription: The first operand for comparing.
-
operand2- Desctription: The second operand for comparing.
- Valid values:
string - Default value:
''
-
operator- Desctription: Comparing operator.
Values are case insensitive (the following names are equal:'isNumeric','isnumeric','ISNUMERIC', etc). - Valid values:
'==''!=''>''<''<=''>=''bool''inArray''isNumeric''isWhitespace'— checks ifoperand1is just white space (an empty string is also considered as white space)'isIncludes'— case-sensitive check ifoperand1containsoperand2
- Default value:
'=='
- Desctription: Comparing operator.
-
trueChunk- Desctription: This value is returning if result is true.
Available placeholders:
[+ddIfParams.operand1+]— containsoperand1value.[+ddIfParams.operand2+]— containsoperand2value.[+ddIfParams.operator+]— containsoperatorvalue.[+any placeholders from theplaceholdersparameter+]
- Valid values:
stringChunkNamestring— use inline templates starting with@CODE:
- Default value:
''
- Desctription: This value is returning if result is true.
Available placeholders:
-
falseChunk- Desctription: This value is returning if result is false.
Available placeholders:
[+ddIfParams.operand1+]— containsoperand1value.[+ddIfParams.operand2+]— containsoperand2value.[+ddIfParams.operator+]— containsoperatorvalue.[+any placeholders from theplaceholdersparameter+]
- Valid values:
stringChunkNamestring— use inline templates starting with@CODE:
- Default value:
''
- Desctription: This value is returning if result is false.
Available placeholders:
-
placeholders- Desctription:
Additional data has to be passed into the
trueChunkandfalseChunk.
Nested objects and arrays are supported too:{"someOne": "1", "someTwo": "test" }=>[+someOne+], [+someTwo+].{"some": {"a": "one", "b": "two"} }=>[+some.a+],[+some.b+].{"some": ["one", "two"] }=>[+some.0+],[+some.1+].
- Valid values:
stringJsonObject— as JSONstringHjsonObject— as HJSONstringQueryFormatted— as Query string- It can also be set as a native PHP object or array (e. g. for calls through
$modx->runSnippet):arrayAssociativeobject
- Default value: —
- Desctription:
Additional data has to be passed into the
debugTitle- Desctription: The title for the System Event log if debugging is needed.
Just set it and watch the System Event log. - Valid values:
string - Default value: —
- Desctription: The title for the System Event log if debugging is needed.
Examples
String comparison
Returns:
Checks if a value exists in an array
Returns:
Check if operand1 contains operand2
Returns:
Checks if a operand1 value is number or not
Returns:
Checks if a operand1 value is just white space or not
Any number of spaces / tabs / new lines / etc are considered as white space. An empty string is also considered as white space.
Returns:
If operand1 contains any non-whitespace characters, falseString will be returned.
Returns:
Number comparison and pass additional data to chunks
Code of the general_good chunk:
Code of the general_goodInexpensive chunk:
Let [*general_price*] be equal to 120, then the snippet returns: