Contents
How to embed JavaScript in a Sitecore MVC site?
This is a technique to allow JavaScript contents to render into a rendering added to a traditional Sitecore MVC page. Doing this allows embedding a JavaScript app within an existing Sitecore MVC site, as opposed to as its own standalone JSS site. This technique executes server-side rendering of the app and returns the rendered markup.
Can a JSS app be placed in a Sitecore rendering?
It is important to understand that JS renderings are an alternate programming model from a JSS app. You cannot use JS renderings to place a regular JSS app within a Sitecore MVC rendering. This is because a JSS app is larger, full-layout-controlling app.
How does the rendercomponent function work in Sitecore?
The renderComponent function is exported and is the function we’ll be specifying to be invoked in our Sitecore JavaScript renderings. The renderComponent function receives rendering data and viewbag data, parses the data for easier consumption by our components, and invokes serverRenderer with the data.
What is the expected function signature for Sitecore?
This is the expected function signature for the Sitecore JavaScript rendering engine. Your rendering is expected to generate html and return that html via the callback(error, result) function. The callback function notifies the rendering engine that rendering is complete and provides the output of your rendering.
How does the Sitecore JavaScript render engine work?
When the rendering is being rendered, the Sitecore JavaScript render engine will use Node.js to load the module and invoke the exported function, passing in serialized data representing the rendering datasource / contents as well as various Sitecore context data.
Can a JS app be hosted on Sitecore?
JS renderings are pre-rendered on the Sitecore server (SSR) and serve working HTML at page load time, however you cannot use them to host JSS apps, because they are only provided with the data for their rendering. JavaScript renderings are also only compatible with Sitecore MVC, and will not work with Web Forms.
What are the arguments of the exported function in Sitecore?
When the Sitecore JavaScript render engine invokes the exported function for the module defined in a JavaScript rendering, the function receives three arguments: callback, data, viewBag. This documentation section is intended to describe the data and viewBag arguments. The general shape of the data argument is as follows: