REST response as HTML string and display it in Home page

0
I have a button in the home page, which on click calls a REST api, which returns a response string which is essentially an HTML page. I have stored it in a variable via a  “Call REST service” in a microflow. For e.g. $myrestresponse = “<!DOCTYPE html> <html> <body> <p>This is some text.</p> </body> </html>” I would now like to display this HTML on the home page in a div element. What is the easiest way to do this? (Since the home page index.html already has the <html>, <body> etc tags, I can remove them from $myrestresponse and keep only the necessary ones)
asked
3 answers
1

Sumit,

One idea:

  • create a FileDocument object
  • use StringToFile (from Community Commons module) to store the HTML in the FileDocument
  • use a download file action to download the file – mark as Display in Browser

Maybe that will have you get started.

Mike

answered
0

I will try that.

I was hoping I could render the html on the fly without having to create intermediate files.

answered
-1

Hi

Mike’s idea works. As an alternative…

For rendering a String attribute in a dom node:

if(this.contextObj!=null){
		var n=dojo.toDom(this.contextObj.get('YourAttributeName'))
    dojo.place(n,this.domNode);
}else{
}

For rendering the actual System.FileDocument in a dom node:

if(this.contextObj!=null){
	dojo.hitch(
		this,
		require(
			["dojo/_base/xhr", "dojo/dom"],
			dojo.hitch(
				this,
				function(xhr, dom){
					var ioArgs = {
							url:
					"/file?guid="+
					this.contextObj.getGuid()+
					"&changedDate="+
					(new Date().getTime()),
							handleAs:"loadNode",
							node: this.domNode
					};
					xhr.contentHandlers.loadNode = function(req){
							var n = dom.byId(ioArgs.node);
							n && (n.innerHTML = req.responseText);
					};
					xhr.get(ioArgs);
				}
		)
		)
	)();
}else{
}

Sample HTMLSnippet widget setup (same in both cases, just your script changes obviously)

answered