PHPackages                             dd/evolutioncms-snippets-ddrunsnippets - 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-ddrunsnippets

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

dd/evolutioncms-snippets-ddrunsnippets
======================================

Snippet runs necessary snippets with necessary params.

4.2.1(1y ago)131PHPPHP &gt;=7.4.0

Since May 12Pushed 1y ago1 watchersCompare

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

READMEChangelog (10)Dependencies (1)Versions (21)Used By (1)

(MODX)EvolutionCMS.snippets.ddRunSnippets
=========================================

[](#modxevolutioncmssnippetsddrunsnippets)

Snippet runs necessary snippets with necessary params. Capabilities:

- Run a few snippets consequentially.
- Snippets results can be sent into parameters names and/or into other snippets values (can repeat this as much as you like).
- Any executed snippet can return either a string or a native PHP array. It is convenient to use with “nested” placeholders (see examples below).
- The snippet result can be returned into the chunk `outputterParams->tpl`, have transferring additional data through the parameter `outputterParams->placeholders`.

See the documentation for a more complete picture.

---

☝ Please note that snippets are run through `\DDTools\Snippet::runSnippet`. This increases performance and saves server resources, but unfortunately you can't run snippets that do not use `\DDTools\Snippet`. Please give us feedback via [Telegram chat](https://t.me/dd_code) if this is critical.

Requires
--------

[](#requires)

- PHP &gt;= 7.4
- [(MODX)EvolutionCMS.libraries.ddTools](https://code.divandesign.ru/modx/ddtools) &gt;= 0.63

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.ddRunSnippets
\DDInstaller::install([
	'url' => 'https://github.com/DivanDesign/EvolutionCMS.snippets.ddRunSnippets',
	'type' => 'snippet',
]);

//Install (MODX)EvolutionCMS.plugins.ddRunSnippets (it is required if you want to use the `snippets->{$snippetName}->runParams->cache` parameters)
\DDInstaller::install([
	'url' => 'https://github.com/DivanDesign/EvolutionCMS.plugins.ddRunSnippets',
	'type' => 'plugin',
]);
```

- If `ddRunSnippets` is not exist on your site, `ddInstaller` will just install it.
- If `ddRunSnippets` 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: `ddRunSnippets`.
2. Description: `4.2.1 Snippet runs necessary snippets with necessary params.`.
3. Category: `Core`.
4. Parse DocBlock: `no`.
5. Snippet code (php): Insert content of the `ddRunSnippets_snippet.php` file from the archive.

#### 2. Elements → Manage Files

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

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

#### 3. Install [(MODX)EvolutionCMS.plugins.ddRunSnippets](https://github.com/DivanDesign/EvolutionCMS.plugins.ddRunSnippets)

[](#3-install-modxevolutioncmspluginsddrunsnippets)

The plugin is required if you want to use the `snippets->{$snippetName}->runParams->cache` parameters.

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

[](#parameters-description)

### Snippets execution parameters

[](#snippets-execution-parameters)

- `snippets`

    - Description: List of snippets to be run. Snippets are called in accordance with the specified order.
    - 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 `\DDTools\Snippet::runSnippet`):
            - `arrayAssociative`
            - `object`
    - **Required**
- `snippets->{$snippetName}`

    - Description: A snippet, when the key is the snippet name and the value is the snippet parameters.
        - By default a snippet result will be equal to `[+snippetName+]` in parameters and chunk (where `snippetName` is the snippet name).
        - But also you can set custom snippet aliases in this parameter using the `'='` delimiter (e. g. `ddGetDocuments=docs`).
        - Every snippet can return either a string or a native PHP array (it is convenient to use with “nested” placeholders, see examples below).
    - Valid values:
        - `object` — an object with snippet parameters (see below)
        - `boolean` — for simple snippet calls without parameters or if you need to use default parameters, you can just pass `true`
    - **Required**
- `snippets->{$snippetName}->{$paramName}`

    - Description: A snippet parameter, when the key is the parameter name and the value is the parameter value.
        - Use `[+snippetName+]` for substitution by any previous snippet execution result in the parameter name or value (where `snippetName` is the snippet name).
        - Or use `[+snippetAlias+]` if specified (e. g. `docs` if the snippet name set as `ddGetDocuments=docs`).
    - Valid values:
        - `mixed` — as opposed to standard CMS calling you can pass not only string parameters to the snippet, any types are supported
    - Default value: —
- `snippets->{$snippetName}->runParams`

    - Description: Additional parameters of snippet running.
    - Valid values: `object`
    - Default value: —
- `snippets->{$snippetName}->runParams->parseResultCompletely`

    - Description: Completely parse result of the snippet by CMS parser.
    - Valid values: `boolean`
    - Default value: — (depends on `snippets_parseEachResultCompletely`)
- `snippets->{$snippetName}->runParams->cache`

    - Description: You can cache snippet result to a specific file.
    - Valid values: `object`
    - Default value: —
- `snippets->{$snippetName}->runParams->cache->resourceId`

    - Description: Resource ID (e. g. document) related to cache.
        It means that the cache file will be destroyed when the document will be updated or deleted.
    - Valid values: `string`
    - **Required**
- `snippets->{$snippetName}->runParams->cache->suffix`

    - Description: Unique cache name for the document.
    - Valid values: `string`
    - **Required**
- `snippets->{$snippetName}->runParams->cache->prefix`

    - Description: Cache file prefix. Useful if you want to cache some custom data that is not related to any documents.
    - Valid values: `string`
    - Default value: `'doc'`
- `snippets_parseEachResultCompletely`

    - Description: Parse result of each snippet by CMS parser.
        Immediately after running each snippet, its result will be parsed by `$modx->parseDocumentSource()`.
    - Valid values: `boolean`
    - Default value: `false`

### Output parameters

[](#output-parameters)

- `outputterParams`

    - Description: Parameters to be passed to the specified outputter.
    - 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 native PHP object or array (e. g. for calls through `\DDTools\Snippet::runSnippet` or `$modx->runSnippet`):
            - `arrayAssociative`
            - `object`
    - Default value: —
- `outputterParams->tpl`

    - Description: Chunk for output results.
        Available placeholders:
        - `[+`*snippetName*`+]` — a snippet result (where `snippetName` is a snippet name)
        - `[+ddRunSnippetsResult.all+]` — results of all executed snippets combined by `''`
        - `[+`*any placeholders from the `outputterParams->placeholders` parameter*`+]`
    - Valid values:
        - `stringChunkName`
        - `string` — use inline templates starting with `@CODE:`
        - `''` — all snippets will be executed but nothing will be returned
    - Default value: `''`
- `outputterParams->placeholders`

    - Description: Additional data has to be passed into `outputterParams->tpl`.
        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: `object`
    - Default value: —

Examples
--------

[](#examples)

All examples are written using [HJSON](https://hjson.github.io/), but if you want you can use vanilla JSON instead.

### Basic example

[](#basic-example)

```
[[ddRunSnippets?
	&snippets=`{
		someSnippet: {
			exampleParam: Example value.
		}

		otherSnippet: {
			someParam: "[+someSnippet+]"
		}

		anotherSnippet: {
			//Results of previous snippets can be used both in parameters names and their values
			"[+otherSnippet+]": "[+someSnippet+]"
		}
	}`
	&outputterParams=`{
		tpl: "@CODE:[+anotherSnippet+]"
	}`
]]

```

### Use alias in snippet names

[](#use-alias-in-snippet-names)

```
[[ddRunSnippets?
	&snippets=`{
		//Run “someSnippet” and save it's result as “snippet1”
		someSnippet=snippet1: {
			exampleParam: First example value.
		}

		//Run “someSnippet” and save it's result as “snippet2”
		someSnippet=snippet2: {
			exampleParam: Second example value.
			//Placeholder “[+snippet1+]” will be replaced to results of previous “someSnippet” call
			exampleParam2: "[+snippet1+]"
		}

		anotherSnippet: {
			someParam: "[+snippet2+]"
			"[+snippet1+]": "[+snippet2+]"
		}
	}`
	&outputterParams=`{
		tpl: "@CODE:[+anotherSnippet+]"
	}`
]]

```

We called snippet `someSnippet` twice with different parameters using two different aliases for each call: `snippet1` and `snippet2`.

### Pass objects and arrays as snippet params

[](#pass-objects-and-arrays-as-snippet-params)

As opposed to standard CMS calling you can pass not only string parameters to a snippet, any types are supported.

```
[[ddRunSnippets?
	&snippets=`{
		someSnippet: {
			//Object as parameter value
			exampleParam1: {
				objectField: “exampleParam1” is an object, not a string.
				otherField: true
			}

			//Array as parameter value
			exampleParam2: [
				“exampleParam2” is an array, not a string
				2.71
			]
		}
	}`
]]

```

### Using results of previous snippets in object-values of parameters

[](#using-results-of-previous-snippets-in-object-values-of-parameters)

```
[[ddRunSnippets?
	&snippets=`{
		someSnippet: {
			exampleParam: Example value.
		}

		otherSnippet: {
			exampleParam1: {
				objectField: “exampleParam1” is an object, not a string.
				otherField: So, “someSnippet” result will be replace the [+someSnippet+] placeholder here.
				anotherField: {
					deepField: Snipepts results placeholders will work fine independent of object depth.
					otherDeepField: The palceholder [+someSnippet+] works here too.
				}
			}
		}
	}`
]]

```

### Native PHP arrays as results of snippets and “nested” placeholders

[](#native-php-arrays-as-results-of-snippets-and-nested-placeholders)

Let the example snippet named `personData` that returs a native PHP array instead of usual string:

```
//Just for example let the snippet do nothing but only return an array :)
return [
	'name' => 'Tamara Eidelman',
	'birthdate' => '1959.12.15',
	'links' => [
		'youtube' => 'https://youtube.com/c/TamaraEidelmanHistory',
		'site' => 'https://eidelman.ru',
	],
];
```

Then execute some snippets via ddRunSnippets:

```
[[ddRunSnippets?
	&snippets=`{
		//Run our example snippet that returns a native PHP array (without parameters in this example case)
		personData: true

		//Run other snippet
		someSnippet: {
			//If we need to pass whole result of the first snippet, just use usual placeholder
			//ddRunSnippet will convert the native PHP array to JSON in this case
			personData: "[+personData+]"
		}

		//Run another snippet
		anotherSnippet: {
			//Also we can use “nested” placeholders to get an item of the snippet result array
			info: "[+personData.name+], [+personData.birthdate+]"
			//And it works with depth
			youtube: "[+personData.links.youtube+]"
		}
	}`
]]

```

### 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.ddRunSnippets
\DDTools\Snippet::runSnippet([
	'name' => 'ddRunSnippets',
	'params' => [
		'snippets' => [
			'someSnippet' => [
				'exampleParam' => 'Example value.',
			],
			'otherSnippet' => [
				'someParam' => '[+someSnippet+]',
			],
			'anotherSnippet' => [
				'[+otherSnippet+]' => '[+someSnippet+]',
			],
		],
		'outputterParams' => [
			'tpl' => '@CODE:[+anotherSnippet+]',
		],
	],
]);
```

Links
-----

[](#links)

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

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance34

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity65

Established project with proven stability

 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 ~85 days

Recently: every ~122 days

Total

19

Last Release

651d ago

Major Versions

1.0.0 → 2.0.02020-05-12

2.5.1b → 3.0.02020-05-13

3.4.0 → 4.0.02023-03-30

PHP version history (3 changes)2.5.1bPHP &gt;=5.4.0

3.3.0PHP &gt;=5.6.0

4.1.0PHP &gt;=7.4.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 (92 commits)")

---

Tags

modxMODX Evoevoevolution-cmsmodx evolutionevo cmsevolutioncmsdivandesigndd studiodd groupddrunsnippetsrun snippetsrun nested snippetscache snippetsadvanced cachecustom cache

### Embed Badge

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

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

PHPackages © 2026

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