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

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

dd/evolutioncms-snippets-ddstash
================================

Save data as JSON or QueryString, then extend if needed and use it later without database queries.

1.3.0(5y ago)02PHPPHP &gt;=5.6.0

Since Oct 31Pushed 1y ago1 watchersCompare

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

READMEChangelog (5)Dependencies (1)Versions (7)Used By (0)

(MODX)EvolutionCMS.snippets.ddStash
===================================

[](#modxevolutioncmssnippetsddstash)

Save data as [JSON](https://en.wikipedia.org/wiki/JSON) or [Query string](https://en.wikipedia.org/wiki/Query_string), then extend if needed and use it later without database queries.

Requires
--------

[](#requires)

- PHP &gt;= 5.6
- [(MODX)EvolutionCMS](https://github.com/evolution-cms/evolution) &gt;= 1.1
- [(MODX)EvolutionCMS.libraries.ddTools](http://code.divandesign.biz/modx/ddtools) &gt;= 0.49.1

Documentation
-------------

[](#documentation)

### Installation

[](#installation)

#### 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: `ddStash`.
2. Description: `1.3 Save data as JSON or QueryString, then extend if needed and use it later without database queries.`.
3. Category: `Core`.
4. Parse DocBlock: `no`.
5. Snippet code (php): Insert content of the `ddStash_snippet.php` file from the archive.

###### 2. Elements → Manage Files

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

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

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

- If `ddStash` is not exist on your site, `ddInstaller` will just install it.
- If `ddStash` is already exist on your site, `ddInstaller` will check it version and update it if needed.

### Parameters description

[](#parameters-description)

- `save`

    - Desctription: Data to save in stash. Nested objects are supported too, see examples below.
    - Valid values:
        - `stringJsonObject` — as [JSON](https://en.wikipedia.org/wiki/JSON)
        - `stringHjsonObject` — as [HJSON](https://hjson.github.io/)
        - `stringQueryFormated` — 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: —
- `save_extendExisting`

    - Desctription: Extend an existing object instead of overwriting it.
    - Valid values:
        - `0`
        - `1`
    - Default value: `0`
- `save_extendExistingWithEmpty`

    - Desctription: Overwrite fields with empty values (see examples below).
        The following values are considered to be empty:
        - `""` — an empty string
        - `[]` — an empty array
        - `{}` — an empty object
        - `null`
    - Valid values:
        - `0`
        - `1`
    - Default value: `1`
- `get`

    - Desctription: Data key for getting from stash.
    - Valid values: `string`
    - Default value: —
- `get_tpl`

    - Desctription: Output template.

        Available placeholders:

        - `[+snippetResult+]` — data from stash
    - Valid values:

        - `stringChunkName`
        - `string` — use inline templates starting with `@CODE:`
    - Default value: `'@CODE:[+snippetResult+]'`
- `storage`

    - Desctription: Data storage.
    - Valid values:
        - `'post'` — `$_POST`
        - `'session'` — `$_SESSION`
    - Default value: `'post'`

### Examples

[](#examples)

#### Save some data

[](#save-some-data)

```
[[ddStash?
	&save=`{
		"userData": {
			"firstName": "John",
			"lastName": "[[ddGetDocumentField?
				&docId=`1`
				&docField=`lastName`
			]]",
			"children": [
				{
					"firstName": "Alice"
				},
				{
					"firstName": "Robert"
				}
			]
		},
		"someData": "someValue"
	}`
]]

```

#### Get saved data

[](#get-saved-data)

##### You can get field value in any depth

[](#you-can-get-field-value-in-any-depth)

```
[[ddStash? &get=`someData`]]

```

Returns `someValue`.

```
[[ddStash? &get=`userData.firstName`]]

```

Returns `John`.

```
[[ddStash? &get=`userData.children.0.firstName`]]

```

Returns `Alice`.

##### Also you can get objects in JSON

[](#also-you-can-get-objects-in-json)

If field value is object or array, it will be returned in JSON format.

###### Get first John child

[](#get-first-john-child)

```
[[ddStash? &get=`userData.children.0`]]

```

Returns:

```
{
	"firstName": "Alice"
}
```

###### Get all John children:

[](#get-all-john-children)

```
[[ddStash? &get=`userData.children`]]

```

Returns:

```
[
	{
		"firstName": "Alice"
	},
	{
		"firstName": "Robert"
	}
]
```

###### Get all data about John

[](#get-all-data-about-john)

```
[[ddStash? &get=`userData`]]

```

Returns:

```
{
	"firstName": "John",
	"lastName": "Doe",
	"children": [
		{
			"firstName": "Alice"
		},
		{
			"firstName": "Robert"
		}
	]
}
```

#### Save: Extend an existing object instead of overwriting it (`&save_extendExisting=`1` `)

[](#save-extend-an-existing-object-instead-of-overwriting-it-save_extendexisting1-)

First you save some object:

```
[[ddStash?
	&save=`{
		"userData": {
			"firstName": "Chuck",
			"lastName": "Doe",
			"children": [
				{
					"firstName": "Alice"
				},
				{
					"firstName": "Robert"
				}
			]
		}
	}`
]]

```

Then if you just save object with the same key (`userData`):

```
[[ddStash?
	&save=`{
		"userData": {
			"middleName": "Ray",
			"lastName": "Norris"
		}
	}`
]]

```

The snippet will overwrite previous saved object completely:

```
[[ddStash? &get=`userData`]]

```

Returns:

```
{
	"middleName": "Ray",
	"lastName": "Norris"
}
```

So, if you want to extend the first object just use the `save_extendExisting` parameter:

```
[[ddStash?
	&save=`{
		"userData": {
			"middleName": "Ray",
			"lastName": "Norris"
		}
	}`
	&save_extendExisting=`1`
]]

```

In this case the snippet will recursive extend the first object with the data from the second:

```
[[ddStash? &get=`userData`]]

```

Returns:

```
{
	"firstName": "Chuck",
	"middleName": "Ray",
	"lastName": "Norris",
	"children": [
		{
			"firstName": "Alice"
		},
		{
			"firstName": "Robert"
		}
	]
}
```

#### Save: Extend without overwriting fields with empty values (`&save_extendExistingWithEmpty=`0` `)

[](#save-extend-without-overwriting-fields-with-empty-values-save_extendexistingwithempty0-)

By default, empty field values (e. g. `''`) are treated as other values and will replace non-empty ones.

```
[[ddStash?
	&save=`{
		"userData": {
			"firstName": "John",
			"lastName": "Tesla",
			"discipline": "Electrical engineering"
		}
	}`
]]
[[ddStash?
	&save=`{
		"userData": {
			"firstName": "Nikola",
			"lastName": ""
		}
	}`
	&save_extendExisting=`1`
]]

```

Returns:

```
{
	"firstName": "Nikola",
	"lastName": "",
	"discipline": "Electrical engineering"
}
```

Empty `lastName` from the second object replaced non-empty `lastName` from the first.

If you want to ignore empty values, just use `save_extendExistingWithEmpty` == `0`:

```
[[ddStash?
	&save=`{
		"userData": {
			"firstName": "John",
			"lastName": "Tesla",
			"discipline": "Electrical engineering"
		}
	}`
]]
[[ddStash?
	&save=`{
		"userData": {
			"firstName": "Nikola",
			"lastName": ""
		}
	}`
	&save_extendExisting=`1`
	&save_extendExistingWithEmpty=`0`
]]
```

Returns:

```
{
	"firstName": "Nikola",
	"lastName": "Tesla",
	"discipline": "Electrical engineering"
}
```

#### 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.ddStash
\DDTools\Snippet::runSnippet([
	'name' => 'ddStash',
	'params' => [
		'get' => 'userData.firstName'
	]
]);
```

Links
-----

[](#links)

- [Home page](https://code.divandesign.biz/modx/ddstash)
- [Telegram chat](https://t.me/dd_code)
- [Packagist](https://packagist.org/packages/dd/evolutioncms-snippets-ddstash)

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance28

Infrequent updates — may be unmaintained

Popularity2

Limited adoption so far

Community7

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

Total

5

Last Release

1846d ago

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

1.3.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 (32 commits)")

---

Tags

modxMODX Evoevostashevolution-cmsmodx evolutionevo cmsddstash

### Embed Badge

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

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

PHPackages © 2026

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