level51/silverstripe-payload-injector

在渲染时将JSON有效载荷注入DOM的实用工具。

安装次数: 1,303

依赖者: 0

建议者: 0

安全: 0

星星: 0

关注者: 2

分支: 0

类型:silverstripe-vendormodule

0.1.5 2023-07-27 14:57 UTC

This package is auto-updated.

Last update: 2024-08-27 17:20:53 UTC


README

License Version

在渲染时将JSON有效载荷注入DOM的实用工具。

要求

  • Silverstripe 4.x

安装

  • composer require level51/silverstripe-payload-injector
  • 清除配置(flush=all)以注册中间件

用法

如果你这样做...

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');
}

...在控制器中,你将得到...

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

...在你的模板中。

配置

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

维护者