Calling Remote Widgets

Last Updated: Jun 8, 2021
documentation for the dotCMS Content Management System

Dotcms supports calling widgets between different servers using the RESTful widget api. For example, if Site A needs to display a widget that exists on Site B, then the webmaster administering Site A can use the widget api to call the “remote widget” on Site B and dynamically display Site B content. There are two methods that can be used to accomplish this.

The Import Tool

Use the import tool to call the widget using the RESTful API, similar to the following:

$import.read("http://YourRemoteSiteB.com/api/widget/id/YourRemoteWidgetID")

Load the remote widget via a Javascript Function

Javascript cost similar to the following may be used to call the remote widget:

<div id="testLoadDiv" >
</div>

<script>
$(function(){
     $('#testLoadDiv').load('http://www.demo.dotcms.com/api/widget/id/8e5e07be-3ee5-4dd1-94b2-39bbd344d167');
});
</script>

Important: Javascript Security

When calling the remote widget via a Javascript function, the following must be added to the REMOTE WIDGET page before the remote widget code. This satisfies browser security and allows the injection of the remote code.

$response.addHeader("Access-Control-Allow-Origin", "http://DomainCallingRemoteWidget.com")

On this page

×

We Dig Feedback

Selected excerpt:

×