PHPackages                             dd/evolutioncms-snippets-ddgetmultiplefield - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. dd/evolutioncms-snippets-ddgetmultiplefield

ActiveModxevo-snippet[Utility &amp; Helpers](/categories/utility)

dd/evolutioncms-snippets-ddgetmultiplefield
===========================================

A snippet for processing, manipulations and custom output structured data (JSON or separated by delimiters strings).

3.10.0(1y ago)022PHPPHP &gt;=5.6.0

Since May 24Pushed 1y ago1 watchersCompare

[ Source](https://github.com/DivanDesign/EvolutionCMS.snippets.ddGetMultipleField)[ Packagist](https://packagist.org/packages/dd/evolutioncms-snippets-ddgetmultiplefield)[ Docs](https://code.divandesign.ru/modx/ddgetmultiplefield)[ RSS](/packages/dd-evolutioncms-snippets-ddgetmultiplefield/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (10)Dependencies (2)Versions (11)Used By (0)

(MODX)EvolutionCMS.snippets.ddGetMultipleField
==============================================

[](#modxevolutioncmssnippetsddgetmultiplefield)

A snippet for processing, manipulations and custom output structured data (JSON or separated by delimiters strings). The fields formed by the [mm\_ddMultipleFields](https://code.divandesign.ru/modx/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` and `inputString_docId` parameters.
- Return of a required values number by values and row number. The `startRow`, `totalRows` and `filter` 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'`). The `sortDir` and `sortBy` parameters.
- Output of data being separated by rows and columns delimeters. The `rowGlue` and `colGlue` parameters.
- Empty values remove before output. The `removeEmptyRows` and `removeEmptyCols` 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). The `rowTpl` and `colTpl` parameters.
- Return of results in a chunk (the `outerTpl` parameter) sending additional data through placeholders. The `placeholders` parameter.

Requires
--------

[](#requires)

- PHP &gt;= 5.6
- [(MODX)EvolutionCMS](https://github.com/evolution-cms/evolution) &gt;= 1.1
- [(MODX)EvolutionCMS.libraries.ddTools](https://code.divandesign.ru/modx/ddtools) &gt;= 0.62
- [(MODX)EvolutionCMS.snippets.ddTypograph](https://code.divandesign.ru/modx/ddtypograph) &gt;= 2.5 (if typography is required)

Installation
------------

[](#installation)

### Using [(MODX)EvolutionCMS.libraries.ddInstaller](https://github.com/DivanDesign/EvolutionCMS.libraries.ddInstaller)

[](#using-modxevolutioncmslibrariesddinstaller)

Just run the following PHP code in your sources or [Console](https://github.com/vanchelo/MODX-Evolution-Ajax-Console):

```
// Include (MODX)EvolutionCMS.libraries.ddInstaller
require_once(
	$modx->getConfig('base_path') .
	'assets/libs/ddInstaller/require.php'
);

// Install (MODX)EvolutionCMS.snippets.ddGetMultipleField
\DDInstaller::install([
	'url' => 'https://github.com/DivanDesign/EvolutionCMS.snippets.ddGetMultipleField',
	'type' => 'snippet'
]);
```

- 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

[](#manually)

#### 1. Elements → Snippets: Create a new snippet with the following data

[](#1-elements--snippets-create-a-new-snippet-with-the-following-data)

1. Snippet name: `ddGetMultipleField`.
2. Description: `3.10 A snippet for processing, manipulations and custom output structured data (JSON or separated by delimiters strings).`.
3. Category: `Core`.
4. Parse DocBlock: `no`.
5. Snippet code (php): Insert content of the `ddGetMultipleField_snippet.php` file from the archive.

#### 2. Elements → Manage Files

[](#2-elements--manage-files)

1. Create a new folder `assets/snippets/ddGetMultipleField/`.
2. Extract the archive to the folder (except `ddGetMultipleField_snippet.php`).

Parameters description
----------------------

[](#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](https://en.wikipedia.org/wiki/JSON) array
        - `stringJsonObject` — [JSON](https://en.wikipedia.org/wiki/JSON) object
        - `stringHjsonObject` — [HJSON](https://hjson.github.io/) object
        - `stringHjsonArray` — [HJSON](https://hjson.github.io/) array
        - `stringQueryFormatted` — [Query string](https://en.wikipedia.org/wiki/Query_string)
        - `stringSeparated` — separated by `inputString_rowDelimiter` and `inputString_colDelimiter`
    - **Required**
- `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.
    - Valid values: `string`
    - Default value: —
- `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: `'||'`
- `inputString_colDelimiter`

    - Description: The input string column delimiter (when `inputString` is not JSON).
    - Valid values:
        - `string`
        - `regexp`
    - Default value: `'::'`
- `startRow`

    - Description: The index of the initial row (indexes start at `0`).
    - Valid values: `integer`
    - Default value: `0`
- `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'`
- `filter`

    - Description: Filter clause for columns.
        - Thus, ```
             0 == 'a' ||
             0 =='b' &&
             1 == 'some' &&
             2 != ''

            ```

            returns the rows where:
            - `0` column is equal to `'a'` **or**
            - `0` column is equal to `'b'` **and**
            - `1` column is equal to `some` **and**
            - `2` column is not equal to `''`.
        - Quoted values are optional, this is valid too: ```
             0 == a ||
             0 == b &&
             1 == some &&
             2 !=

            ```
        - Double quotes are also supported as single quotes: ```
             0 == "a" ||
             0 == "b" &&
             1 == "some" &&
             2 != ""

            ```
        - 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'`.
    - Valid values:
        - `stringCommaSeparated`
        - `array`
    - Default value: `'0'`
- `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: —
- `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`.
    - Valid values: `string`
    - Default value: `''`
- `colGlue`

    - Description: The string that combines columns while rendering.
        - It can be used along with `colTpl` and `rowTpl`.
    - Valid values: `string`
    - Default value: `''`
- `rowTpl`

    - Description: The template for row rendering (`outputFormat` has to be == `'html'`).
        - Available placeholders:
            - `[+rowNumber+]` — index of current row, starts at `1`
            - `[+rowNumber.zeroBased+]` — index of current row, starts at `0`
            - `[+rowKey+]` — key of current row, it is usefull for objects or associative arrays in `inputString`, 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 by `colGlue`
            - `[+allColumnValuesObjectJson+]` — values of all columns as a JSON object, where keys are original column keys, values are values
    - Valid values:
        - `stringChunkName`
        - `string` — use inline templates starting with `@CODE:`
    - Default value: —
- `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: —
- `colTpl[$i]`

    - Description: The template for column rendering.
        - Available placeholders:
            - `[+val+]` — value of the column
            - `[+columnIndex+]` — index of the column, starts at `0`
            - `[+columnKey+]` — key of the column, it is usefull for objects or associative arrays in `inputString`, for indexed arrays the placeholder is equal to `[+columnIndex+]`
            - `[+rowNumber+]` — index of current row, starts at `1`
            - `[+rowNumber.zeroBased+]` — index of current row, starts at `0`
            - `[+rowKey+]` — key of current row, it is usefull for objects or associative arrays in `inputString`, for indexed arrays the placeholder is equal to `[+rowNumber.zeroBased+]`
            - `[+total+]` — total number of rows
            - `[+resultTotal+]` — total number of returned rows
    - Valid values:
        - `stringChunkName`
        - `string` — use inline templates starting with `@CODE:`
        - `'null'` — specifies rendering without a template
    - Default value: `'null'`
- `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)
    - Valid values:
        - `stringChunkName`
        - `string` — use inline templates starting with `@CODE:`
    - Default value: —
- `placeholders`

    - Description: Additional data has to be passed into the `outerTpl`, `rowTpl` and `colTpl` templates.
        - Nested objects and arrays are supported too:
            - `{"someOne": "1", "someTwo": "test" }` =&gt; `[+someOne+], [+someTwo+]`.
            - `{"some": {"a": "one", "b": "two"} }` =&gt; `[+some.a+]`, `[+some.b+]`.
            - `{"some": ["one", "two"] }` =&gt; `[+some.0+]`, `[+some.1+]`.
    - Valid values:
        - `stringJsonObject` — as [JSON](https://en.wikipedia.org/wiki/JSON)
        - `stringHjsonObject` — as [HJSON](https://hjson.github.io/)
        - `stringQueryFormatted` — as [Query string](https://en.wikipedia.org/wiki/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: —
- `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`
- `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.
    - Valid values: `string`
    - Default value: —
- `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: —

Examples
--------

[](#examples)

### Output `images` with description

[](#output-images-with-description)

The initial string (locates in `images` TV):

```
assets/images/some_img1.jpg::Image 1||assets/images/some_img2.jpg::Image 2

```

The snippet call in the template of a document:

```
[[ddGetMultipleField?
	&inputString=`[*images*]`
	&rowTpl=`images_item`
]]

```

The `images_item` chunk code:

```
[+col1+]:

```

Returns:

```
Image 1:

Image 2:

```

### Output images from JSON using original column keys in row template

[](#output-images-from-json-using-original-column-keys-in-row-template)

```
[[ddGetMultipleField?
	&inputString=`[
		{
			"src": "assets/images/some_img1.jpg",
			"alt": "Image 1"
		},
		{
			"src": "assets/images/some_img2.jpg",
			"alt": "Image 2"
		}
	]`
	&rowTpl=`@CODE:`
]]

```

Returns:

```

```

### Output rows with dynamic number of columns using the `[+allColumnValues+]` placeholder and the `rowTpl`, `colGlue` parameters

[](#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:

```
[[ddGetMultipleField?
	&inputString=`{
		"First prices": [
			"$100",
			"$120"
		],
		"Second prices": [
			"$300",
			"$320",
			"$350"
		],
		"Third prices": [
			"$50"
		]
	}`
	&outerTpl=`@CODE:[+result+]`
	&rowTpl=`@CODE:[+rowKey+]: [+allColumnValues+]`
	&colGlue=`, `
]]

```

Returns:

```

	First prices: $100, $120
	Second prices: $300, $320, $350
	Third prices: $50

```

### The data getting and output from `prices` TV of the document with ID = `25` in table format if the data is not empty

[](#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:

```
Tasty apples::100::kg||Usual nails::5 000::centner||Cats::865::pieces

```

The snippet call (wherever):

```
[[ddGetMultipleField?
	&inputString_docField=`prices`
	&inputString_docId=`25`
	&outerTpl=`prices`
	&rowTpl=`prices_item`
]]

```

The `prices_item` chunk code:

```

	[+rowNumber+]
	[+col0+]
	[+col1+]/[+col2+]

```

The `prices` chunk code:

```
Price table

	[+result+]

```

Returns:

```
Price table

		1
		Tasty apples
		100/kg

		2
		Usual nails
		5 000/centner

		3
		Cats
		865/pieces

```

### Return document tags separated by commas using a regular expression in `inputString_rowDelimiter`

[](#return-document-tags-separated-by-commas-using-a-regular-expression-in-inputstring_rowdelimiter)

[(MODX)EvolutionCMS.plugins.ManagerManager.mm\_widget\_tags](https://code.divandesign.ru/modx/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:

```
Cats, Dogs,Whales , Bears , Elephants

```

The snippet call:

```
[[ddGetMultipleField?
	&inputString=`[*tags*]`
	&inputString_rowDelimiter=`/\s*,\s*/`
	&rowGlue=`, `
	&rowTpl=`tags_item`
]]

```

The `tags_item` chunk contents:

```
[+col0+]
```

Returns:

```
Cats,
Dogs,
Whales,
Bears,
Elephants
```

### Passing additional data into templates via `placeholders`

[](#passing-additional-data-into-templates-via-placeholders)

```
[[ddGetMultipleField?
	&inputString=`Grey::8 kg::loves meat||Red::6 kg::vegetarian`
	&outerTpl=`cats`
	&rowTpl=`cats_item`
	&colTpl=`cats_item_color,null,null`
	&placeholders=`{
		"kind": "cats",
		"price": "not for sale",
		"colorTitle": "He has a nice thick coat."
	}`
]]

```

The `cats` chunk code (`[+kind+]` will be replaced to `cats`):

```
Our [+resultTotal+] favorite [+kind+].

	[+result+]

```

The `cats_item` chunk code (`[+price+]` will be replaced to `not for sale`):

```
[+rowNumber+]. [+col0+], [+col1+], [+col2+] — [+price+].
```

The `cats_item_color` chunk code (`[+colorTitle+]` will be replaced to `He has a nice thick coat.`):

```
[+val+]
```

Returns:

```
Our 2 favorite cats.

	1. Grey, 8 kg, loves meat — not for sale.
	2. Red, 6 kg, vegetarian — not for sale.

```

### Filter by column value (the `filter` parameter)

[](#filter-by-column-value-the-filter-parameter)

```
[[ddGetMultipleField?
	&inputString=`[
		[
			"John Bon Jovi",
			"musician",
			"Bon Jovi"
		],
		[
			"Steve Jobs",
			"businessman",
			"Apple"
		],
		[
			"Roger Waters",
			"musician",
			"Pink Floyd"
		],
		[
			"Robbie Williams",
			"musician",
			""
		],
		[
			"Hugh Laurie",
			"actor",
			""
		]
	]`
	&filter=`
		1 == 'musician' &&
		2 != '' ||
		0 == 'Hugh Laurie'
	`
	&outputFormat=`json`
]]

```

Returns:

```
[
	[
		"John Bon Jovi",
		"musician",
		"Bon Jovi"
	],
	[
		"Roger Waters",
		"musician",
		"Pink Floyd"
	],
	[
		"Hugh Laurie",
		"actor",
		""
	]
]
```

### Sort a JSON object by multiple columns (parameters → `sortBy`, `sortDir`)

[](#sort-a-json-object-by-multiple-columns-parameters--sortby-sortdir)

```
[[ddGetMultipleField?
	&inputString=`{
		"Albert Einstein": {
			"number": "18",
			"born": "1879.03.14",
			"died": "1955.04.18"
		},
		"Alan Turing": {
			"number": "42",
			"born": "1912.06.23",
			"died": "1954.06.07"
		},
		"Nikola Tesla": {
			"number": "7",
			"born": "1856.07.10",
			"died": "1943.01.07"
		},
		"Marie Curie": {
			"number": "42",
			"born": "1867.11.07",
			"died": "1934.07.04"
		},
		"Dmitri Mendeleev": {
			"number": "7",
			"born": "1834.02.08",
			"died": "1907.02.02"
		}
	}`
	&sortDir=`ASC`
	&sortBy=`number,born`
	&outputFormat=`json`
]]

```

Returns:

```
{
	"Dmitri Mendeleev": {
		"number": "7",
		"born": "1834.02.08",
		"died": "1907.02.02"
	},
	"Nikola Tesla": {
		"number": "7",
		"born": "1856.07.10",
		"died": "1943.01.07"
	},
	"Albert Einstein": {
		"number": "18",
		"born": "1879.03.14",
		"died": "1955.04.18"
	},
	"Marie Curie": {
		"number": "42",
		"born": "1867.11.07",
		"died": "1934.07.04"
	},
	"Alan Turing": {
		"number": "42",
		"born": "1912.06.23",
		"died": "1954.06.07"
	}
}
```

### Run the snippet through `\DDTools\Snippet::runSnippet` without DB and eval

[](#run-the-snippet-through-ddtoolssnippetrunsnippet-without-db-and-eval)

```
// Include (MODX)EvolutionCMS.libraries.ddTools
require_once(
	$modx->getConfig('base_path') .
	'assets/libs/ddTools/modx.ddtools.class.php'
);

// Run (MODX)EvolutionCMS.snippets.ddGetMultipleField
\DDTools\Snippet::runSnippet([
	'name' => 'ddGetMultipleField',
	'params' => [
		'inputString' => '[
			[
				"assets/images/example1.png",
				"Example image 1"
			],
			[
				"assets/images/example2.png",
				"Example image 2"
			]
		]',
		'rowTpl' => '@CODE:',
	],
]);
```

*It is hard to write here all possible examples so if here is something that you do not completely understand, please ask us.*

Links
-----

[](#links)

- [Home page](https://code.divandesign.ru/modx/ddgetmultiplefield)
- [Telegram chat](https://t.me/dd_code)
- [Packagist](https://packagist.org/packages/dd/evolutioncms-snippets-ddgetmultiplefield)
- [GitHub](https://github.com/DivanDesign/EvolutionCMS.snippets.ddGetMultipleField)

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance34

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~195 days

Recently: every ~206 days

Total

9

Last Release

620d ago

PHP version history (2 changes)3.5.0PHP &gt;=5.4.0

3.6.0PHP &gt;=5.6.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/09b81986267e62b5fde1473b40aa6f11f7bc26c1c29d5f80f2768c8788e08110?d=identicon)[dd](/maintainers/dd)

---

Top Contributors

[![Ronef](https://avatars.githubusercontent.com/u/1333424?v=4)](https://github.com/Ronef "Ronef (91 commits)")

---

Tags

modxMODX Evoevoevolution-cmsmodx evolutionevo cmsevolutioncmsdivandesigndd studiodd groupmm\_ddMultipleFieldsddgetmultiplefieldmultiple fieldsget multiple fieldsort json

### Embed Badge

![Health badge](/badges/dd-evolutioncms-snippets-ddgetmultiplefield/health.svg)

```
[![Health](https://phpackages.com/badges/dd-evolutioncms-snippets-ddgetmultiplefield/health.svg)](https://phpackages.com/packages/dd-evolutioncms-snippets-ddgetmultiplefield)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
