Download the PHP package dd/evolutioncms-snippets-ddgetmultiplefield without Composer
On this page you can find all versions of the php package dd/evolutioncms-snippets-ddgetmultiplefield. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download dd/evolutioncms-snippets-ddgetmultiplefield
More information about dd/evolutioncms-snippets-ddgetmultiplefield
Files in dd/evolutioncms-snippets-ddgetmultiplefield
Package evolutioncms-snippets-ddgetmultiplefield
Short Description A snippet for processing, manipulations and custom output structured data (JSON or separated by delimiters strings).
License
Homepage https://code.divandesign.ru/modx/ddgetmultiplefield
Informations about the package evolutioncms-snippets-ddgetmultiplefield
(MODX)EvolutionCMS.snippets.ddGetMultipleField
A snippet for processing, manipulations and custom output structured data (JSON or separated by delimiters strings). The fields formed by the mm_ddMultipleFields widget values output gets more convinient with the snippet.
Features:
- Field value getting of a required document (TV) by its ID. The
inputString_docField
andinputString_docId
parameters. - Return of a required values number by values and row number. The
startRow
,totalRows
andfilter
parameters. - Return of a required value by columns number. The
columns
parameter. - Rows sorting (including multiple sorting) by columns values before returning (
'ASC'
,'DESC'
,'RAND'
,'REVERSE'
). ThesortDir
andsortBy
parameters. - Output of data being separated by rows and columns delimeters. The
rowGlue
andcolGlue
parameters. - Empty values remove before output. The
removeEmptyRows
andremoveEmptyCols
parameters. - Values typography before output (the snippet ddTypograph is used). The
typography
parameter. - Result URL encode. The
urlencode
parameter. - Result JSON encode. The
outputFormat
parameter. - Values returning by the given templates (chunks) of rows and columns (also the
[+rowNumber+]
and[+rowNumber.zeroBased+]
placeholders with a row number is available in the row and column templates). TherowTpl
andcolTpl
parameters. - Return of results in a chunk (the
outerTpl
parameter) sending additional data through placeholders. Theplaceholders
parameter.
Requires
- PHP >= 5.6
- (MODX)EvolutionCMS >= 1.1
- (MODX)EvolutionCMS.libraries.ddTools >= 0.62
- (MODX)EvolutionCMS.snippets.ddTypograph >= 2.5 (if typography is required)
Installation
Using (MODX)EvolutionCMS.libraries.ddInstaller
Just run the following PHP code in your sources or Console:
- If
ddGetMultipleField
is not exist on your site,ddInstaller
will just install it. - If
ddGetMultipleField
is already exist on your site,ddInstaller
will check it version and update it if needed.
Manually
1. Elements → Snippets: Create a new snippet with the following data
- Snippet name:
ddGetMultipleField
. - Description:
<b>3.10</b> A snippet for processing, manipulations and custom output structured data (JSON or separated by delimiters strings).
. - Category:
Core
. - Parse DocBlock:
no
. - Snippet code (php): Insert content of the
ddGetMultipleField_snippet.php
file from the archive.
2. Elements → Manage Files
- Create a new folder
assets/snippets/ddGetMultipleField/
. - Extract the archive to the folder (except
ddGetMultipleField_snippet.php
).
Parameters description
From the pair of inputString
/ inputString_docField
parameters one is required.
-
inputString
- Description: The input string containing values.
- Also supports JSON with any nesting level.
- Valid values:
stringJsonArray
— JSON arraystringJsonObject
— JSON objectstringHjsonObject
— HJSON objectstringHjsonArray
— HJSON arraystringQueryFormatted
— Query stringstringSeparated
— separated byinputString_rowDelimiter
andinputString_colDelimiter
- Required
- Description: The input string containing values.
-
inputString_docField
- Description: The name of the document field/TV which value is required to get.
- If the parameter is passed then the input string will be taken from the field / TV and
inputString
will be ignored.
- If the parameter is passed then the input string will be taken from the field / TV and
- Valid values:
string
- Default value: —
- Description: The name of the document field/TV which value is required to get.
-
inputString_docId
- Description: ID of the document which field/TV value is required to get.
- Valid values:
integer
- Default value:
$modx->documentIdentifier
(the current document ID)
-
inputString_rowDelimiter
- Description: The input string row delimiter (when
inputString
is not JSON). - Valid values:
string
regexp
- Default value:
'||'
- Description: The input string row delimiter (when
-
inputString_colDelimiter
- Description: The input string column delimiter (when
inputString
is not JSON). - Valid values:
string
regexp
- Default value:
'::'
- Description: The input string column delimiter (when
-
startRow
- Description: The index of the initial row (indexes start at
0
). - Valid values:
integer
- Default value:
0
- Description: The index of the initial row (indexes start at
-
totalRows
- Description: The maximum number of rows to return.
- Valid values:
integer
'all'
— all rows will be returned
- Default value:
'all'
-
columns
- Description: The indexes of columns to return (indexes start at
0
). - Valid values:
stringCommaSeparated
array
'all'
— all columns will be returned
- Default value:
'all'
- Description: The indexes of columns to return (indexes start at
-
filter
-
Description: Filter clause for columns.
-
Thus,
returns the rows where:
0
column is equal to'a'
or0
column is equal to'b'
and1
column is equal tosome
and2
column is not equal to''
.
-
Quoted values are optional, this is valid too:
-
Double quotes are also supported as single quotes:
- Spaces, tabs and line breaks are optional, this is valid too:
0==a||0==b&&1==some&&2!=
.
-
- Valid values:
stringSeparated
- Default value: —
-
-
removeEmptyRows
- Description: Is it required to remove empty rows?
- Valid values:
0
1
- Default value:
1
-
removeEmptyCols
- Description: Is it required to remove empty columns?
- Valid values:
0
1
- Default value:
1
-
sortBy
- Description: The index of the column to sort by (indexes start at
0
).- The parameter also takes comma-separated values for multiple sort, e.g.
'0,1'
.
- The parameter also takes comma-separated values for multiple sort, e.g.
- Valid values:
stringCommaSeparated
array
- Default value:
'0'
- Description: The index of the column to sort by (indexes start at
-
sortDir
- Description: Rows sorting direction (case insensitive).
- Valid values:
'ASC'
— the rows will be returned in ascending order'DESC'
— the rows will be returned in descending order'RAND'
— the rows will be returned in random order'REVERSE'
— the rows will be returned in reversed order''
— the rows will be returned without sorting (as set)
- Default value:
''
-
typography
- Description: The comma separated indexes of the columns which values have to be corrected (indexes start at
0
).- If unset, there will be no correction.
- Valid values:
stringCommaSeparated
array
- Default value: —
- Description: The comma separated indexes of the columns which values have to be corrected (indexes start at
-
outputFormat
- Description: Result output format (case insensitive).
- Valid values:
'html'
'json'
'array'
'htmlarray'
- Default value:
'html'
-
rowGlue
- Description: The string that combines rows while rendering.
- It can be used along with
rowTpl
.
- It can be used along with
- Valid values:
string
- Default value:
''
- Description: The string that combines rows while rendering.
-
colGlue
- Description: The string that combines columns while rendering.
- It can be used along with
colTpl
androwTpl
.
- It can be used along with
- Valid values:
string
- Default value:
''
- Description: The string that combines columns while rendering.
-
rowTpl
- Description: The template for row rendering (
outputFormat
has to be =='html'
).- Available placeholders:
[+rowNumber+]
— index of current row, starts at1
[+rowNumber.zeroBased+]
— index of current row, starts at0
[+rowKey+]
— key of current row, it is usefull for objects or associative arrays ininputString
, for indexed arrays the placeholder is equal to[+rowNumber.zeroBased+]
[+total+]
— total number of rows[+resultTotal+]
— total number of returned rows[+col
columnNumber+]
(e. g.[+col0+]
,[+col1+]
, etc) — column values, when columnNumber is zero-based column number[+
columnKey+]
— column values, when columnKey is original column key (see examples below)[+
columnKey.
nestedProperty+]
,[+col
columnNumber.
nestedProperty+]
— values of a nested properties, if a column value is an object[+allColumnValues+]
— values of all columns combined bycolGlue
[+allColumnValuesObjectJson+]
— values of all columns as a JSON object, where keys are original column keys, values are values
- Available placeholders:
- Valid values:
stringChunkName
string
— use inline templates starting with@CODE:
- Default value: —
- Description: The template for row rendering (
-
colTpl
- Description: The comma-separated list of templates for column rendering (
outputFormat
has to be =='html'
).- If the number of templates is lesser than the number of columns then the last passed template will be used to render the rest of the columns.
- Valid values:
stringCommaSeparated
array
- Default value: —
- Description: The comma-separated list of templates for column rendering (
-
colTpl[$i]
- Description: The template for column rendering.
- Available placeholders:
[+val+]
— value of the column[+columnIndex+]
— index of the column, starts at0
[+columnKey+]
— key of the column, it is usefull for objects or associative arrays ininputString
, for indexed arrays the placeholder is equal to[+columnIndex+]
[+rowNumber+]
— index of current row, starts at1
[+rowNumber.zeroBased+]
— index of current row, starts at0
[+rowKey+]
— key of current row, it is usefull for objects or associative arrays ininputString
, for indexed arrays the placeholder is equal to[+rowNumber.zeroBased+]
[+total+]
— total number of rows[+resultTotal+]
— total number of returned rows
- Available placeholders:
- Valid values:
stringChunkName
string
— use inline templates starting with@CODE:
'null'
— specifies rendering without a template
- Default value:
'null'
- Description: The template for column rendering.
-
outerTpl
- Description: Wrapper template (
outputFormat
has to be !='array'
).- Available placeholders:
[+result+]
— snippet result[+total+]
— total number of rows[+resultTotal+]
— total number of returned rows[+rowY.colX+]
— value (Y
— row number,X
— column number)[+rowKey.colX+]
— value (Key
— row key,X
— column number)
- Available placeholders:
- Valid values:
stringChunkName
string
— use inline templates starting with@CODE:
- Default value: —
- Description: Wrapper template (
-
placeholders
- Description: Additional data has to be passed into the
outerTpl
,rowTpl
andcolTpl
templates.- 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+]
.
- Nested objects and arrays are supported too:
- 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
):arrayAssociative
object
- Default value: —
- Description: Additional data has to be passed into the
-
urlencode
- Description: Is it required to URL encode the result?
outputFormat
has to be !='array'
.- URL encoding is used according to RFC 3986.
- Valid values:
0
1
- Default value:
0
- Description: Is it required to URL encode the result?
-
totalRowsToPlaceholder
- Description: The name of the global (MODX)Evolution placeholder that holds the total number of rows.
- The placeholder won't be set if
totalRowsToPlaceholder
is empty.
- The placeholder won't be set if
- Valid values:
string
- Default value: —
- Description: The name of the global (MODX)Evolution placeholder that holds the total number of rows.
resultToPlaceholder
- Description: The name of the global (MODX)Evolution placeholder that holds the snippet result.
- The result will be returned in a regular manner if the parameter is empty.
- Valid values:
string
- Default value: —
- Description: The name of the global (MODX)Evolution placeholder that holds the snippet result.
Examples
Output images
with description
The initial string (locates in images
TV):
The snippet call in the template of a document:
The images_item
chunk code:
Returns:
Output images from JSON using original column keys in row template
Returns:
Output rows with dynamic number of columns using the [+allColumnValues+]
placeholder and the rowTpl
, colGlue
parameters
Let the first row contains 2 columns, the second — 3, the third — 1:
Returns:
The data getting and output from prices
TV of the document with ID = 25
in table format if the data is not empty
The initial field value:
The snippet call (wherever):
The prices_item
chunk code:
The prices
chunk code:
Returns:
Return document tags separated by commas using a regular expression in inputString_rowDelimiter
(MODX)EvolutionCMS.plugins.ManagerManager.mm_widget_tags is applied to tags
TV where document tags are stored in tags
.
User fills in the tags separated by commas, while the field may be filled both with spaces on the sides and without them.
tags
TV value:
The snippet call:
The tags_item
chunk contents:
Returns:
Passing additional data into templates via placeholders
The cats
chunk code ([+kind+]
will be replaced to cats
):
The cats_item
chunk code ([+price+]
will be replaced to not for sale
):
The cats_item_color
chunk code ([+colorTitle+]
will be replaced to He has a nice thick coat.
):
Returns:
Filter by column value (the filter
parameter)
Returns:
Sort a JSON object by multiple columns (parameters → sortBy
, sortDir
)
Returns:
Run the snippet through \DDTools\Snippet::runSnippet
without DB and eval
It is hard to write here all possible examples so if here is something that you do not completely understand, please ask us.
Links
All versions of evolutioncms-snippets-ddgetmultiplefield with dependencies
dd/evolutioncms-libraries-ddtools Version >=0.62.0
dd/evolutioncms-snippets-ddtypograph Version >=2.5.0