Concept
An editor which is embedded in your HTML pages can be interacted with using our JavaScript API. See Embedding an Editor in your own portals
There are many reasons a team would want to do this. Some examples are:
Updating variables on document load
Connecting to a custom widget
Building a partial or complete custom interface
Creating a “Save” button or an auto-save feature
Connection To CHILI publisher
You cannot communicate with the CHILI publisher directly due to the editor running in an iframe and browser security blocking JavaScript communication across iframes.
Therefore, if you want to utilize our JavaScript API across iframes you need to utilize our plugin: publisher-connector
You can install PublisherConnector via npm
npm i @chili-publish/publisher-connector
or through yarn
yarn add @chili-publish/publisher-connector
Or you can use the version from unpkg.com in your <script/> tags:
https://unpkg.com/@chili-publish/publisher-connector@latest/dist/PublisherConnector.min.js
Which one should I use?
If you utilize the NPM package, you will get all the benefits of TypeScript declaration files. However, you will need to use a module bundler like Webpack, Parcel, Rollup, etc. to package your JavaScript files for the web.
If you want to use this library in your integration without requiring a build phase, or you just want something simple, you can utilize the unpkg.com URL
Once you have decided, it is time to begin your integration. There are three steps:
Create an instance of the PublishConnector
Listen to event for document to be fully rendered
Start making modifications
Create an instance of the PublishConnector
To create an instance of the PublisherConnector, you will need to use the “build” method and pass in the iframe element.
<body> <iframe id="editor-iframe" style="width:1200px; height:800px" src="https://example.chili-publish.online/example/editor_html.aspx?doc=3d178228-a9b9-49d0-90d9-c1c8f8b67f05&apiKey=Sczs1ruhiZcaFiqg0G07gMFMq07X+SG2o8KlW8oAeZGvqoB1a0YvkbeZU1wJK15aIhANgZmhg+13NQlxpBEq7Q=="></iframe> <script type="module"> import {PublisherConnector} from 'https://unpkg.com/@chili-publish/publisher-connector@latest/dist/PublisherConnector.min.js'; const iframe = document.getElementById("editor-iframe"); (async () => { const publisherConnector = await PublisherConnector.build(iframe); const documentName = await publisherConnector.getObject("document.name"); console.log(documentName); })(); </script> </body>