Skip to content
Utility for injecting JSON payload into the DOM at render time
PHP
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
_config
src
LICENSE
README.md
composer.json

README.md

Silverstripe Payload Injector

License Version

Utility for injecting JSON payload into the DOM at render time.

Requirements

  • Silverstripe 4.x

Installation

  • composer require level51/silverstripe-payload-injector
  • Flush config (flush=all) to register the middleware

Usage

If you do...

public function index() {
  PayloadInjector::singleton()->stage([
    'title'       => 'Silverstripe Payload Injector',
    'description' => 'Utility for injecting JSON payload into the DOM at render time.'
  ]);
  
  return $this->renderWidth('MainView');
}

...in a controller you will have...

    ...
    <script>window.payload = {"title":"Silverstripe Payload Injector","description":"Utility for injecting JSON payload into the DOM at render time."}</script>
  </body>
</html>

...in your template.

Config

Level51\PayloadInjector\PayloadInjector:
  merge_recursive: true     # Merge payload recursively to avoid overriding existing data (default: true)

Maintainer

You can’t perform that action at this time.